2002-10-18 Duncan Mak <duncan@ximian.com>
authorDuncan Mak <duncan@mono-cvs.ximian.com>
Sat, 19 Oct 2002 00:02:38 +0000 (00:02 -0000)
committerDuncan Mak <duncan@mono-cvs.ximian.com>
Sat, 19 Oct 2002 00:02:38 +0000 (00:02 -0000)
* XmlDocument.cs: Applied a patch by Atsushi Enomoto
<ginga@kit.hi-ho.ne.jp>.

* XmlDocumentTests.cs: Apply a patch from Atsushi Enomoto
<ginga@kit.hi-ho.ne.jp>.

svn path=/trunk/mcs/; revision=8376

mcs/class/System.XML/System.Xml.Xsl/XslTransform.cs
mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlDocument.cs
mcs/class/System.XML/Test/ChangeLog
mcs/class/System.XML/Test/XmlDocumentTests.cs

index 8af60b669752d2953e7e2907b7351ca92bd7542e..dee1a34394575e29a11bfe6d53859719a486c0e0 100644 (file)
@@ -21,10 +21,9 @@ namespace System.Xml.Xsl
                #endregion\r
 \r
                #region Constructors\r
-\r
-               [MonoTODO]\r
                public XslTransform ()\r
                {\r
+                       stylesheet_file = String.Empty;\r
                }\r
 \r
                #endregion\r
index 925d3b35c0fb2dc77c04deb175a74555bfa08cb4..936561fbb832e29ef862c1a9e236f4f1420ada3d 100644 (file)
@@ -1,3 +1,8 @@
+2002-10-18  Duncan Mak  <duncan@ximian.com>
+
+       * XmlDocument.cs: Applied a patch by Atsushi Enomoto
+       <ginga@kit.hi-ho.ne.jp>.
+
 2002-10-12  A.Enomoto <ginga@kit.hi-ho.ne.jp>
 
        * XmlDocument.cs (ImportNode): Implemented
index 03a2d42caf7362d4112789a4da13c8b495bd658d..2ae9186c2754b8412edc7404326ac81a3bef5217 100644 (file)
@@ -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 ();
index c1a5a894ad3aeb3fb19a4deaa6fe99f6a01bc1d8..fd343b8a24e37eca3d5f831341de3050c4e2427a 100644 (file)
@@ -1,3 +1,8 @@
+2002-10-18  Duncan Mak  <duncan@ximian.com>
+
+       * XmlDocumentTests.cs: Apply a patch from Atsushi Enomoto
+       <ginga@kit.hi-ho.ne.jp>.
+
 2002-09-29  Nick Drochak  <ndrochak@gol.com>
 
        * XmlTextReaderTest.cs (AssertEndDocument): Add messages for Asserts()
index 4da1e550c059346cfc9dd71b6f9b875cf83286f6..da8b1149b4e95f40e74ddfd0e5cdf4ddf54ea10c 100644 (file)
@@ -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
+               }
        }
 }