Browse Source

2002-10-18 Duncan Mak <[email protected]>

	* XmlDocument.cs: Applied a patch by Atsushi Enomoto
	<[email protected]>.

	* XmlDocumentTests.cs: Apply a patch from Atsushi Enomoto
	<[email protected]>.

svn path=/trunk/mcs/; revision=8376
Duncan Mak 23 năm trước cách đây
mục cha
commit
0a40887d3b

+ 1 - 2
mcs/class/System.XML/System.Xml.Xsl/XslTransform.cs

@@ -21,10 +21,9 @@ namespace System.Xml.Xsl
 		#endregion
 
 		#region Constructors
-
-		[MonoTODO]
 		public XslTransform ()
 		{
+			stylesheet_file = String.Empty;
 		}
 
 		#endregion

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

@@ -1,3 +1,8 @@
+2002-10-18  Duncan Mak  <[email protected]>
+
+	* XmlDocument.cs: Applied a patch by Atsushi Enomoto
+	<[email protected]>.
+
 2002-10-12  A.Enomoto <[email protected]>
 
 	* XmlDocument.cs (ImportNode): Implemented

+ 45 - 26
mcs/class/System.XML/System.Xml/XmlDocument.cs

@@ -395,11 +395,17 @@ namespace System.Xml
 		[MonoTODO]
 		public virtual XmlNode ImportNode (XmlNode node, bool deep)
 		{
+			// How to resolve default attribute values?
 			switch(node.NodeType)
 			{
 				case XmlNodeType.Attribute:
-					XmlAttribute a = node as XmlAttribute;
-					return this.CreateAttribute(a.Prefix, a.LocalName, a.NamespaceURI);
+					{
+						XmlAttribute src_att = node as XmlAttribute;
+						XmlAttribute dst_att = this.CreateAttribute(src_att.Prefix, src_att.LocalName, src_att.NamespaceURI);
+						// TODO: resolve default attribute values
+						dst_att.Value = src_att.Value;
+						return dst_att;
+					}
 
 				case XmlNodeType.CDATA:
 					return this.CreateCDataSection(node.Value);
@@ -411,43 +417,54 @@ namespace System.Xml
 					throw new XmlException("Document cannot be imported.");
 
 				case XmlNodeType.DocumentFragment:
-					XmlDocumentFragment df = this.CreateDocumentFragment();
-					if(deep)
 					{
-						foreach(XmlNode n in node.ChildNodes)
+						XmlDocumentFragment df = this.CreateDocumentFragment();
+						if(deep)
 						{
-							df.AppendChild(this.ImportNode(n, deep));
+							foreach(XmlNode n in node.ChildNodes)
+							{
+								df.AppendChild(this.ImportNode(n, deep));
+							}
 						}
+						return df;
 					}
-					return df;
 
 				case XmlNodeType.DocumentType:
 					throw new XmlException("DocumentType cannot be imported.");
 
 				case XmlNodeType.Element:
-					XmlElement src = node as XmlElement;
-					XmlElement dst = this.CreateElement(src.Prefix, src.LocalName, src.NamespaceURI);
-					if(deep)
 					{
-						foreach(XmlNode n in src.ChildNodes)
-							dst.AppendChild(this.ImportNode(n, deep));
+						XmlElement src = (XmlElement)node;
+						XmlElement dst = this.CreateElement(src.Prefix, src.LocalName, src.NamespaceURI);
+						foreach(XmlAttribute attr in src.Attributes)
+						{
+							// TODO: create default attribute values
+							dst.SetAttributeNode((XmlAttribute)this.ImportNode(attr, deep));
+						}
+						if(deep)
+						{
+							foreach(XmlNode n in src.ChildNodes)
+								dst.AppendChild(this.ImportNode(n, deep));
+						}
+						return dst;
 					}
-					return dst;
 
-				//case XmlNodeType.EndElement:
-				//	throw new NotImplementedException ();
-				//case XmlNodeType.EndEntity:
-				//	throw new NotImplementedException ();
-				//case XmlNodeType.Entity:
-				//	throw new NotImplementedException ();
+				case XmlNodeType.EndElement:
+					throw new XmlException ("Illegal ImportNode call for NodeType.EndElement");
+				case XmlNodeType.EndEntity:
+					throw new XmlException ("Illegal ImportNode call for NodeType.EndEntity");
+				case XmlNodeType.Entity:
+					throw new NotImplementedException ();
 
+				// [2002.10.14] CreateEntityReference not implemented.
 				case XmlNodeType.EntityReference:
-					return this.CreateEntityReference(node.Name);
+					throw new NotImplementedException("ImportNode of EntityReference not implemented mainly because CreateEntityReference was implemented in the meantime.");
+//					return this.CreateEntityReference(node.Name);
 
-				//case XmlNodeType.None:
-				//	throw new NotImplementedException ();
-				//case XmlNodeType.Notation:
-				//	throw new NotImplementedException ();
+				case XmlNodeType.None:
+					throw new XmlException ("Illegal ImportNode call for NodeType.None");
+				case XmlNodeType.Notation:
+					throw new NotImplementedException ();
 
 				case XmlNodeType.ProcessingInstruction:
 					XmlProcessingInstruction pi = node as XmlProcessingInstruction;
@@ -462,8 +479,10 @@ namespace System.Xml
 				case XmlNodeType.Whitespace:
 					return this.CreateWhitespace(node.Value);
 
-				//case XmlNodeType.XmlDeclaration:
-				//	throw new NotImplementedException ();
+				// I don't know how to test it...
+				case XmlNodeType.XmlDeclaration:
+				//	return this.CreateNode(XmlNodeType.XmlDeclaration, String.Empty, node.Value);
+					throw new NotImplementedException ();
 
 				default:
 					throw new NotImplementedException ();

+ 5 - 0
mcs/class/System.XML/Test/ChangeLog

@@ -1,3 +1,8 @@
+2002-10-18  Duncan Mak  <[email protected]>
+
+	* XmlDocumentTests.cs: Apply a patch from Atsushi Enomoto
+	<[email protected]>.
+
 2002-09-29  Nick Drochak  <[email protected]>
 
 	* XmlTextReaderTest.cs (AssertEndDocument): Add messages for Asserts()

+ 49 - 0
mcs/class/System.XML/Test/XmlDocumentTests.cs

@@ -744,5 +744,54 @@ namespace MonoTests.System.Xml
 			nextSibling = node.NextSibling;
 			AssertNull ("Expected removed node's next sibling to be null.", nextSibling);
 		}
+
+		// ImportNode
+		public void TestImportNode ()
+		{
+			XmlNode n;
+
+			string xlinkURI = "http://www.w3.org/1999/XLink";
+			string xml1 = "<?xml version='1.0' encoding='utf-8' ?><foo xmlns:xlink='" + xlinkURI + "'><bar a1='v1' xlink:href='#foo'><baz><![CDATA[cdata section.\n\titem 1\n\titem 2\n]]>From here, simple text node.</baz></bar></foo>";
+			document.LoadXml(xml1);
+			XmlDocument newDoc = new XmlDocument();
+			newDoc.LoadXml("<hoge><fuga /></hoge>");
+			XmlElement bar = document.DocumentElement.FirstChild as XmlElement;
+
+			// Attribute
+			n = newDoc.ImportNode(bar.GetAttributeNode("href", xlinkURI), true);
+			AssertEquals("#ImportNode.Attr.NS.LocalName", "href", n.LocalName);
+			AssertEquals("#ImportNode.Attr.NS.NSURI", xlinkURI, n.NamespaceURI);
+			AssertEquals("#ImportNode.Attr.NS.Value", "#foo", n.Value);
+
+			// CDATA
+			n = newDoc.ImportNode(bar.FirstChild.FirstChild, true);
+			AssertEquals("#ImportNode.CDATA", "cdata section.\n\titem 1\n\titem 2\n", n.Value);
+
+			// Element
+			XmlElement e = newDoc.ImportNode(bar, true) as XmlElement;
+			AssertEquals("#ImportNode.Element.Name", "bar", e.Name);
+			AssertEquals("#ImportNode.Element.Attr", "#foo", e.GetAttribute("href", xlinkURI));
+			AssertEquals("#ImportNode.Element.deep", "baz", e.FirstChild.Name);
+
+			// Entity Reference:
+			//   [2002/10/14] CreateEntityReference was not implemented.
+//			document.LoadXml("<!DOCTYPE test PUBLIC 'dummy' [<!ENTITY FOOENT 'foo'>]><root>&FOOENT;</root>");
+//			n = newDoc.ImportNode(document.DocumentElement.FirstChild);
+//			AssertEquals("#ImportNode.EntityReference", "FOOENT", n.Name);
+//			AssertEquals("#ImportNode.EntityReference", "foo_", n.Value);
+
+			// Processing Instruction
+			document.LoadXml("<foo><?xml-stylesheet href='foo.xsl' ?></foo>");
+			XmlProcessingInstruction pi = (XmlProcessingInstruction)newDoc.ImportNode(document.DocumentElement.FirstChild, false);
+			AssertEquals("#ImportNode.ProcessingInstruction.Name", "xml-stylesheet", pi.Name);
+			AssertEquals("#ImportNode.ProcessingInstruction.Data", "href='foo.xsl'", pi.Data.Trim());
+			
+			// Text
+			document.LoadXml(xml1);
+			n = newDoc.ImportNode((XmlText)bar.FirstChild.ChildNodes[1], true);
+			AssertEquals("#ImportNode.Text", "From here, simple text node.", n.Value);
+
+			// Whitespace
+		}
 	}
 }