Selaa lähdekoodia

2003-07-28 Atsushi Enomoto <[email protected]>

	* DTDValidatingReader.cs : (Read,ValidateAttributes,ReadAttributeValue)
	  attribute declaration should be got independently of elementdecl.
	* XmlAttribute.cs :
	  Added internal SetDefault() to mark as default.
	  Removed InnerText implementation that is just the same as XmlNode.
	* XmlDocument.cs : id shouldn't be removed from table at 'trying' to
	  get matching elements.  ReadAttributeNode() now sets default mark.
	* XmlElement.cs : WriteTo() should ignore default attributes.
	* XmlTextWriter.cs : shuold allow valid name char such as digits.

svn path=/trunk/mcs/; revision=16783
Atsushi Eno 22 vuotta sitten
vanhempi
sitoutus
e4fa13f616

+ 12 - 0
mcs/class/System.XML/System.Xml/ChangeLog

@@ -1,3 +1,15 @@
+2003-07-28  Atsushi Enomoto <[email protected]>
+
+	* DTDValidatingReader.cs : (Read,ValidateAttributes,ReadAttributeValue)
+	  attribute declaration should be got independently of elementdecl.
+	* XmlAttribute.cs :
+	  Added internal SetDefault() to mark as default.
+	  Removed InnerText implementation that is just the same as XmlNode.
+	* XmlDocument.cs : id shouldn't be removed from table at 'trying' to
+	  get matching elements.  ReadAttributeNode() now sets default mark.
+	* XmlElement.cs : WriteTo() should ignore default attributes.
+	* XmlTextWriter.cs : shuold allow valid name char such as digits.
+
 2003-07-27  Piers Haken	<[email protected]>
 
 	* XmlQualifiedName.cs : fields should never be null

+ 23 - 20
mcs/class/System.XML/System.Xml/DTDValidatingReader.cs

@@ -298,21 +298,22 @@ namespace Mono.Xml
 				currentElement = Name;
 				elementStack.Push (reader.Name);
 				automataStack.Push (currentAutomata);
-				if (decl != null) {	// i.e. not invalid
+				if (decl != null)	// i.e. not invalid
 					currentAutomata = decl.ContentModel.GetAutomata ();
 
+				DTDAttListDeclaration attList = dtd.AttListDecls [currentElement];
+				if (attList != null) {
 					// check attributes
-					if (decl.Attributes == null) {
-						if (reader.HasAttributes) {
-							HandleError (String.Format ("Attributes are found on element {0} while it has no attribute definitions.",decl.Name),
-								XmlSeverityType.Error);
-							// FIXME: validation recovery code here.
-						}
+					ValidateAttributes (attList);
+				} else {
+					if (reader.HasAttributes) {
+						HandleError (String.Format (
+							"Attributes are found on element {0} while it has no attribute definitions.", currentElement),
+							XmlSeverityType.Error);
+						// FIXME: validation recovery code here.
 					}
-					else
-						ValidateAttributes (decl);
-				} else
 					SetupValidityIgnorantAttributes ();
+				}
 
 				// If it is empty element then directly check end element.
 				if (reader.IsEmptyElement)
@@ -353,7 +354,9 @@ namespace Mono.Xml
 					break;
 
 				DTDElementDeclaration elem = dtd.ElementDecls [elementStack.Peek () as string];
-				if (!elem.IsMixedContent) {
+				// Here element should have been already validated, so
+				// if no matching declaration is found, simply ignore.
+				if (elem != null && !elem.IsMixedContent) {
 					HandleError (String.Format ("Current element {0} does not allow character data content.", elementStack.Peek () as string),
 						XmlSeverityType.Error);
 					// FIXME: validation recovery code here.
@@ -399,7 +402,7 @@ namespace Mono.Xml
 				throw ex;
 		}
 
-		private void ValidateAttributes (DTDElementDeclaration decl)
+		private void ValidateAttributes (DTDAttListDeclaration decl)
 		{
 			while (reader.MoveToNextAttribute ()) {
 				string attrName = reader.Name;
@@ -425,7 +428,7 @@ namespace Mono.Xml
 				valueBuilder.Length = 0;
 				attributeValues.Add (attrName, attrValue);
 
-				DTDAttributeDefinition def = decl.Attributes [reader.Name];
+				DTDAttributeDefinition def = decl [reader.Name];
 				if (def == null) {
 					HandleError (String.Format ("Attribute {0} is not declared.", reader.Name),
 						XmlSeverityType.Error);
@@ -478,7 +481,7 @@ namespace Mono.Xml
 			}
 			// Check if all required attributes exist, and/or
 			// if there is default values, then add them.
-			foreach (DTDAttributeDefinition def in decl.Attributes.Definitions)
+			foreach (DTDAttributeDefinition def in decl.Definitions)
 				if (!attributes.Contains (def.Name)) {
 					if (def.OccurenceType == DTDAttributeOccurenceType.Required) {
 						HandleError (String.Format ("Required attribute {0} was not found.", decl.Name),
@@ -503,6 +506,10 @@ namespace Mono.Xml
 				consumedAttribute = true;
 				return true;
 			}
+			else if (IsDefault) {
+				consumedAttribute = true;
+				return true;
+			}
 			else
 				return reader.ReadAttributeValue ();
 		}
@@ -670,9 +677,7 @@ namespace Mono.Xml
 					sourceTextReader != null && 
 					sourceTextReader.Normalization) {
 				DTDAttributeDefinition def = 
-					dtd.ElementDecls [currentElement]
-					.Attributes [currentAttribute]
-					as DTDAttributeDefinition;
+					dtd.AttListDecls [currentElement] [currentAttribute] as DTDAttributeDefinition;
 				valueBuilder.Append (rawValue);
 				valueBuilder.Replace ('\r', ' ');
 				valueBuilder.Replace ('\n', ' ');
@@ -702,9 +707,7 @@ namespace Mono.Xml
 				// This check also covers value node of default attributes.
 				if (IsDefault) {
 					DTDAttributeDefinition def = 
-						dtd.ElementDecls [currentElement]
-						.Attributes [currentAttribute]
-						as DTDAttributeDefinition;
+						dtd.AttListDecls [currentElement] [currentAttribute] as DTDAttributeDefinition;
 					return sourceTextReader != null && sourceTextReader.Normalization ?
 						def.NormalizedDefaultValue : def.DefaultValue;
 				}

+ 8 - 16
mcs/class/System.XML/System.Xml/XmlAttribute.cs

@@ -33,7 +33,7 @@ namespace System.Xml
 		protected internal XmlAttribute (
 			string prefix, 
 			string localName, 
-			string namespaceURI, 
+			string namespaceURI,
 			XmlDocument doc) : base (doc)
 		{
 			if (prefix == null)
@@ -74,27 +74,14 @@ namespace System.Xml
 
 		public override string InnerText {
 			get {
-				StringBuilder builder = new StringBuilder ();
-				AppendChildValues (this, builder);
-				return builder.ToString ();
-                        }
+				return base.InnerText;
+			}
 
 			set {
 				Value = value;
 			}
 		}
 
-		private void AppendChildValues (XmlNode parent, StringBuilder builder)
-		{
-			XmlNode node = parent.FirstChild;
-			
-			while (node != null) {
-				builder.Append (node.Value);
-				AppendChildValues (node, builder);
-				node = node.NextSibling;
-                        }
-                }
-		
 		[MonoTODO ("Setter is incomplete(XmlTextReader.ReadAttribute is incomplete;No resolution for xml:lang/space")]
 		public override string InnerXml {
 			get {
@@ -232,6 +219,11 @@ namespace System.Xml
 			return node;
 		}
 
+		internal void SetDefault ()
+		{
+			isDefault = true;
+		}
+
 		// Parent of XmlAttribute must be null
 		internal void SetOwnerElement (XmlElement el) {
 			ownerElement = el;

+ 3 - 1
mcs/class/System.XML/System.Xml/XmlDocument.cs

@@ -463,7 +463,7 @@ namespace System.Xml
 			if (attr == null)
 				return null;
 			if (attr.OwnerElement == null || !attr.OwnerElement.IsRooted) {
-				idTable.Remove (id);
+//				idTable.Remove (id);
 				return null;
 			}
 			return attr;
@@ -693,6 +693,8 @@ namespace System.Xml
 				res = reader.MoveToAttribute (attribute.Name);
 			else 
 				res = reader.MoveToAttribute (attribute.LocalName, attribute.NamespaceURI);
+			if (reader.IsDefault)
+				attribute.SetDefault ();
 			return attribute;
 		}
 

+ 3 - 2
mcs/class/System.XML/System.Xml/XmlElement.cs

@@ -368,8 +368,9 @@ namespace System.Xml
 		{
 			w.WriteStartElement(Prefix, LocalName, NamespaceURI);
 
-			foreach(XmlNode attributeNode in Attributes)
-				attributeNode.WriteTo(w);
+			foreach(XmlAttribute attributeNode in Attributes)
+				if (attributeNode.Specified)
+					attributeNode.WriteTo(w);
 			if (IsEmpty)
 				w.WriteEndElement ();
 			else {

+ 7 - 4
mcs/class/System.XML/System.Xml/XmlTextWriter.cs

@@ -486,10 +486,13 @@ namespace System.Xml
 			WriteEndElementInternal (true);
 		}
 
-		private void CheckValidChars (string name, bool firstOnlyLetter)
+		private void CheckValidName (string name, bool firstOnlyLetter)
 		{
+			if (firstOnlyLetter && !XmlConstructs.IsNameStart (name [0]))
+				throw new ArgumentException ("There is an invalid character: '" + name [0] +
+							     "'", "name");
 			foreach (char c in name) {
-				if (XmlConvert.IsInvalid (c, firstOnlyLetter))
+				if (!XmlConstructs.IsName (c))
 					throw new ArgumentException ("There is an invalid character: '" + c +
 								     "'", "name");
 			}
@@ -497,13 +500,13 @@ namespace System.Xml
 
 		public override void WriteName (string name)
 		{
-			CheckValidChars (name, true);
+			CheckValidName (name, true);
 			w.Write (name);
 		}
 
 		public override void WriteNmToken (string name)
 		{
-			CheckValidChars (name, false);
+			CheckValidName (name, false);
 			w.Write (name);
 		}