Example #1
0
		private void ResolveInternalEntityReplacementText (DTDEntityBase decl)
		{
			string value = decl.LiteralEntityValue;
			int len = value.Length;
			ClearValueBuffer ();
			for (int i = 0; i < len; i++) {
				int ch = value [i];
				int end = 0;
				string name;
				switch (ch) {
				case '&':
					i++;
					end = value.IndexOf (';', i);
					if (end < i + 1)
						throw new XmlException (decl, decl.BaseURI, "Invalid reference markup.");
					// expand charref
					if (value [i] == '#') {
						i++;
						ch = GetCharacterReference (decl, value, ref i, end);
						if (XmlChar.IsInvalid (ch))
							throw NotWFError ("Invalid character was used to define parameter entity.");

					} else {
						name = value.Substring (i, end - i);
						if (!XmlChar.IsName (name))
							throw NotWFError (String.Format ("'{0}' is not a valid entity reference name.", name));
						// don't expand "general" entity.
						AppendValueChar ('&');
						valueBuffer.Append (name);
						AppendValueChar (';');
						i = end;
						break;
					}
					if (XmlChar.IsInvalid (ch))
						throw new XmlException (decl, decl.BaseURI, "Invalid character was found in the entity declaration.");
					AppendValueChar (ch);
					break;
				case '%':
					i++;
					end = value.IndexOf (';', i);
					if (end < i + 1)
						throw new XmlException (decl, decl.BaseURI, "Invalid reference markup.");
					name = value.Substring (i, end - i);
					valueBuffer.Append (GetPEValue (name));
					i = end;
					break;
				default:
					AppendValueChar (ch);
					break;
				}
			}
			decl.ReplacementText = CreateValueString ();

			ClearValueBuffer ();
		}
Example #2
0
		private int GetCharacterReference (DTDEntityBase li, string value, ref int index, int end)
		{
			int ret = 0;
			if (value [index] == 'x') {
				try {
					ret = int.Parse (value.Substring (index + 1, end - index - 1), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
				} catch (FormatException) {
					throw new XmlException (li, li.BaseURI, "Invalid number for a character reference.");
				}
			} else {
				try {
					ret = int.Parse (value.Substring (index, end - index), CultureInfo.InvariantCulture);
				} catch (FormatException) {
					throw new XmlException (li, li.BaseURI, "Invalid number for a character reference.");
				}
			}
			index = end;
			return ret;
		}
Example #3
0
		private void ResolveExternalEntityReplacementText (DTDEntityBase decl)
		{
			if (decl.SystemId != null && decl.SystemId.Length > 0) {
				// FIXME: not always it should be read in Element context
				XmlTextReader xtr = new XmlTextReader (decl.LiteralEntityValue, XmlNodeType.Element, null);
				xtr.SkipTextDeclaration ();
				if (decl is DTDEntityDeclaration && DTD.EntityDecls [decl.Name] == null) {
					// GE - also checked as valid contents
					StringBuilder sb = new StringBuilder ();
					xtr.Normalization = this.Normalization;
					xtr.Read ();
					while (!xtr.EOF)
						sb.Append (xtr.ReadOuterXml ());
					decl.ReplacementText = sb.ToString ();
				}
				else
					// PE
					decl.ReplacementText = xtr.GetRemainder ().ReadToEnd ();
			}
			else
				decl.ReplacementText = decl.LiteralEntityValue;
		}