Selaa lähdekoodia

2003-06-25 Atsushi Enomoto <[email protected]>

	* XmlDocumentNavigator.cs : Fixed IsEmptyElement. It treats <foo></foo>
	  as non-empty, and XmlElement's IsEmpty is designed as such.
	  Fixed MoveToFirst() and MoveToNext() not to move to xmldecl nor
	  doctype node.
	* XmlNode.cs : Fixed XPathNodeType. It should throw an exception
	  instead of returning undefined enum value.
	  Modified some code comments.
	* XmlWriter.cs : Fixed WriteNode () to use WriteFullEndElement()
	  when XmlReader's node is not at empty element or at EndElement.
	  Fixed XmlDeclaration's standalone check.

svn path=/trunk/mcs/; revision=15632
Atsushi Eno 22 vuotta sitten
vanhempi
sitoutus
80f8dc00d4

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

@@ -1,3 +1,16 @@
+2003-06-25  Atsushi Enomoto <[email protected]>
+
+	* XmlDocumentNavigator.cs : Fixed IsEmptyElement. It treats <foo></foo>
+	  as non-empty, and XmlElement's IsEmpty is designed as such.
+	  Fixed MoveToFirst() and MoveToNext() not to move to xmldecl nor 
+	  doctype node. 
+	* XmlNode.cs : Fixed XPathNodeType. It should throw an exception
+	  instead of returning undefined enum value.
+	  Modified some code comments.
+	* XmlWriter.cs : Fixed WriteNode () to use WriteFullEndElement() 
+	  when XmlReader's node is not at empty element or at EndElement. 
+	  Fixed XmlDeclaration's standalone check.
+
 2003-06-21  Atsushi Enomoto <[email protected]>
 
 	* XmlTextReader.cs : removed CRLFs. Fixed private InitializeContext()

+ 27 - 5
mcs/class/System.XML/System.Xml/XmlDocumentNavigator.cs

@@ -63,7 +63,8 @@ namespace System.Xml
 
 		public override bool IsEmptyElement {
 			get {
-				return node.NodeType == XmlNodeType.Element && !HasChildren;
+				return node.NodeType == XmlNodeType.Element 
+					&& ((XmlElement) node).IsEmpty;
 			}
 		}
 
@@ -151,7 +152,7 @@ namespace System.Xml
 		public override string GetAttribute (string localName, string namespaceURI)
 		{
 			XmlElement el = Node as XmlElement;
-			return (el != null) ? el.GetAttribute (localName, namespaceURI) : String.Empty;
+			return el != null ? el.GetAttribute (localName, namespaceURI) : String.Empty;
 		}
 
 		public override string GetNamespace (string name)
@@ -199,7 +200,10 @@ namespace System.Xml
 		public override bool MoveToFirst ()
 		{
 			if (node.NodeType != XmlNodeType.Attribute && node.ParentNode != null) {
-				node = node.ParentNode.FirstChild;
+				MoveToParent ();
+				// Follow these 2 steps so that we can skip 
+				// some types of nodes .
+				MoveToFirstChild ();
 				return true;
 			}
 			return false;
@@ -269,10 +273,28 @@ namespace System.Xml
 		public override bool MoveToNext ()
 		{
 			if (node.NextSibling != null) {
-				node = node.NextSibling;
+				if (node.ParentNode != null && node.ParentNode.NodeType == XmlNodeType.Document) {
+					XmlNode n = node.NextSibling;
+					while (n != null) {
+						switch (n.NodeType) {
+						case XmlNodeType.DocumentType:
+						case XmlNodeType.XmlDeclaration:
+							n = n.NextSibling;
+							continue;
+						}
+						break;
+					}
+					if (n != null)
+						node = n;
+					else
+						return false;
+				}
+				else
+					node = node.NextSibling;
 				return true;
 			}
-			return false;
+			else
+				return false;
 		}
 
 		public override bool MoveToNextAttribute ()

+ 11 - 8
mcs/class/System.XML/System.Xml/XmlNode.cs

@@ -166,7 +166,7 @@ namespace System.Xml
 
 		internal virtual XPathNodeType XPathNodeType {
 			get {
-				return (XPathNodeType) (-1);
+				throw new InvalidOperationException ();
 			}
 		}
 
@@ -177,7 +177,7 @@ namespace System.Xml
 
 				WriteTo (xtw);
 
-				return sw.GetStringBuilder ().ToString ();
+				return sw.ToString ();
 			}
 		}
 
@@ -290,8 +290,11 @@ namespace System.Xml
 		{
 			// I assume that insertAfter(n1, n2) equals to InsertBefore(n1, n2.PreviousSibling).
 
-			// I took this way because rather than calling InsertAfter() from InsertBefore()
-			//   because current implementation of 'NextSibling' looks faster than 'PreviousSibling'.
+			// I took this way because current implementation 
+			// Calling InsertAfter() from InsertBefore() is
+			// subsequently to use 'NextSibling' which is
+			// faster than 'PreviousSibling' (these children are 
+			// forward-only linked list).
 			XmlNode argNode = null;
 			if(refChild != null)
 				argNode = refChild.NextSibling;
@@ -515,10 +518,10 @@ namespace System.Xml
 			return ((XmlDocumentNavigator) iter.Current).Node;
 		}
 
-		internal void SetParentNode (XmlNode parent)
-		{
-			parentNode = parent;
-		}
+//		internal void SetParentNode (XmlNode parent)
+//		{
+//			parentNode = parent;
+//		}
 
 		[MonoTODO]
 		public virtual bool Supports (string feature, string version)

+ 2 - 2
mcs/class/System.XML/System.Xml/XmlWriter.cs

@@ -203,13 +203,13 @@ namespace System.Xml
 				WriteWhitespace (reader.Value);
 				break;
 			case XmlNodeType.EndElement:
-				WriteEndElement ();
+				WriteFullEndElement ();
 				break;
 			case XmlNodeType.EndEntity:
 				break;
 			case XmlNodeType.XmlDeclaration:
 				string st = reader.GetAttribute ("standalone");
-				if (st != String.Empty)
+				if (st != null && st != String.Empty)
                                         WriteStartDocument (st.ToLower () == "yes");
 				else
 					WriteStartDocument ();