Added implementation of namepsace qualified GetElementsByTagName courtesy of
authorJason Diamond <injektilo@mono-cvs.ximian.com>
Thu, 22 Aug 2002 13:11:55 +0000 (13:11 -0000)
committerJason Diamond <injektilo@mono-cvs.ximian.com>
Thu, 22 Aug 2002 13:11:55 +0000 (13:11 -0000)
Matt Hunter <xrkune@tconl.com>.

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

mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlDocument.cs
mcs/class/System.XML/System.Xml/XmlElement.cs
mcs/class/System.XML/Test/ChangeLog
mcs/class/System.XML/Test/XmlDocumentTests.cs
mcs/class/System.XML/Test/XmlElementTests.cs

index 81fedfef6308276fdbde4f26f275735571dfddb1..3f2769fbbddbf0b730acffac2377bd2081fa95e6 100644 (file)
@@ -1,3 +1,9 @@
+2002-08-22  Jason Diamond <jason@injektilo.org>
+
+       * XmlDocument.cs, XmlElement.cs: Added implementation of namepsace
+       qualified GetElementsByTagName courtesy of Matt Hunter 
+       <xrkune@tconl.com>.
+
 2002-08-19  Jason Diamond <jason@injektilo.org>
 
        * XmlDocument.cs, XmlElement.cs: Added implementation of 
index a3c4bd3b800868508d1209e7dac86dfc1cf71fc0..54fbc3c8fcf3a0c89a8a777d2bb180478905ebe7 100644 (file)
@@ -343,25 +343,27 @@ namespace System.Xml
                public virtual XmlNodeList GetElementsByTagName (string name)
                {
                        ArrayList nodeArrayList = new ArrayList ();
-                       this.searchNodesRecursively (this, name, nodeArrayList);
+                       this.searchNodesRecursively (this, name, String.Empty, nodeArrayList);
                        return new XmlNodeArrayList (nodeArrayList);
                }
 
-               private void searchNodesRecursively (XmlNode argNode, string argName, ArrayList argArrayList)
+               private void searchNodesRecursively (XmlNode argNode, string argName, string argNamespaceURI, 
+                       ArrayList argArrayList)
                {
                        XmlNodeList xmlNodeList = argNode.ChildNodes;
                        foreach (XmlNode node in xmlNodeList){
-                               if (node.Name.Equals (argName))
+                               if (node.LocalName.Equals (argName) && node.NamespaceURI.Equals (argNamespaceURI))
                                        argArrayList.Add (node);
                                else    
-                                       this.searchNodesRecursively (node, argName, argArrayList);
+                                       this.searchNodesRecursively (node, argName, argNamespaceURI, argArrayList);
                        }
                }
 
-               [MonoTODO]
                public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
                {
-                       throw new NotImplementedException();
+                       ArrayList nodeArrayList = new ArrayList ();
+                       this.searchNodesRecursively (this, localName, namespaceURI, nodeArrayList);
+                       return new XmlNodeArrayList (nodeArrayList);
                }
 
                private XmlNodeType GetNodeTypeFromString (string nodeTypeString)
index 9a11634a67214b9fd6086e7eb04ac1e896289af8..be669c5fc74412db71721c7afd5f96b8cf4e5c02 100644 (file)
@@ -170,27 +170,23 @@ namespace System.Xml
                public virtual XmlNodeList GetElementsByTagName (string name)
                {
                        ArrayList nodeArrayList = new ArrayList ();
-                       this.searchNodesRecursively (this, name, nodeArrayList);
+                       this.searchNodesRecursively (this, name, String.Empty, nodeArrayList);
                        return new XmlNodeArrayList (nodeArrayList);
                }
 
-               private void searchNodesRecursively (XmlNode argNode, string argName, ArrayList argArrayList)
+               private void searchNodesRecursively (XmlNode argNode, string argName, string argNamespaceURI, 
+                       ArrayList argArrayList)
                {
                        XmlNodeList xmlNodeList = argNode.ChildNodes;
-                       foreach (XmlNode node in xmlNodeList){
-                               if (node.Name.Equals (argName))
+                       foreach (XmlNode node in xmlNodeList)
+                       {
+                               if (node.LocalName.Equals (argName) && node.NamespaceURI.Equals (argNamespaceURI))
                                        argArrayList.Add (node);
                                else    
-                                       this.searchNodesRecursively (node, argName, argArrayList);
+                                       this.searchNodesRecursively (node, argName, argNamespaceURI, argArrayList);
                        }
                }
 
-               [MonoTODO]
-               public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
-               {
-                       throw new NotImplementedException ();
-               }
-
                [MonoTODO]
                public virtual bool HasAttribute (string name)
                {
index 1ad4fa6afc1f28001a335a30484d7e5244942e95..a3d4249efcd891dd32ea27fba1eec745d858991f 100644 (file)
@@ -1,6 +1,12 @@
+2002-08-22  Jason Diamond <jason@injektilo.org>
+
+       * XmlDocumentTests.cs, XmlElementTests.cs: Added tests for 
+       namespace qualified GetElementsByTagName courtesy of Matt Hunter 
+       <xrkune@tconl.com>.
+
 2002-08-19  Jason Diamond <jason@injektilo.org>
 
-       * XmlDocument.cs, XmlElement.cs: Added tests for 
+       * XmlDocumentTests.cs, XmlElementTests.cs: Added tests for 
        GetElementsByTagName courtesy of Matt Hunter <xrkune@tconl.com>.
 
 2002-08-17  Jason Diamond  <jason@injektilo.org>
index 427cc70091d2bf93bf8879d715aceaebcb1a659b..5ede6bf749db76112a70ef71904133c8d3cf4f89 100644 (file)
@@ -547,6 +547,29 @@ namespace MonoTests.System.Xml
                        AssertEquals ("GetElementsByTagName (string) returned incorrect count.", 4, bookList.Count);
                }
 
+               public void TestGetElementsByTagNameUsingNameSpace ()
+               {
+                       StringBuilder xml = new StringBuilder ();
+                       xml.Append ("<?xml version=\"1.0\" ?><library xmlns:North=\"http://www.foo.com\"");
+                       xml.Append ("xmlns:South=\"http://www.goo.com\"><North:book type=\"non-fiction\"> ");
+                       xml.Append ("<North:title type=\"intro\">XML Fun</North:title> " );
+                       xml.Append ("<North:author>John Doe</North:author> " );
+                       xml.Append ("<North:price>34.95</North:price></North:book> " );
+                       xml.Append ("<South:book type=\"fiction\"> " );
+                       xml.Append ("<South:title>Bear and the Dragon</South:title> " );
+                       xml.Append ("<South:author>Tom Clancy</South:author> " );
+                        xml.Append ("<South:price>6.95</South:price></South:book> " );
+                       xml.Append ("<South:book type=\"fiction\"><South:title>Bourne Identity</South:title> " );
+                       xml.Append ("<South:author>Robert Ludlum</South:author> " );
+                       xml.Append ("<South:price>9.95</South:price></South:book></library>");
+
+                       MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml.ToString ()));
+                       document = new XmlDocument ();
+                       document.Load (memoryStream);
+                       XmlNodeList bookList = document.GetElementsByTagName ("book", "http://www.goo.com");
+                       AssertEquals ("GetElementsByTagName (string, uri) returned incorrect count.", 2, bookList.Count);
+               }
+
        
                public void TestInnerAndOuterXml ()
                {
index 31fda435418aad5ed53ca565b7d74233548eae4f..734b36108dd49bb62642aa44a2361a4abe5a2979 100644 (file)
@@ -154,6 +154,29 @@ namespace MonoTests.System.Xml
                        AssertEquals ("GetElementsByTagName (string) returned incorrect count.", 4, bookList.Count);
                }
 
+               public void TestGetElementsByTagNameUsingNameSpace ()
+               {
+                       StringBuilder xml = new StringBuilder ();
+                       xml.Append ("<?xml version=\"1.0\" ?><library xmlns:North=\"http://www.foo.com\"");
+                       xml.Append ("xmlns:South=\"http://www.goo.com\"><North:book type=\"non-fiction\"> ");
+                       xml.Append ("<North:title type=\"intro\">XML Fun</North:title> " );
+                       xml.Append ("<North:author>John Doe</North:author> " );
+                       xml.Append ("<North:price>34.95</North:price></North:book> " );
+                       xml.Append ("<South:book type=\"fiction\"> " );
+                       xml.Append ("<South:title>Bear and the Dragon</South:title> " );
+                       xml.Append ("<South:author>Tom Clancy</South:author> " );
+                       xml.Append ("<South:price>6.95</South:price></South:book> " );
+                       xml.Append ("<South:book type=\"fiction\"><South:title>Bourne Identity</South:title> " );
+                       xml.Append ("<South:author>Robert Ludlum</South:author> " );
+                       xml.Append ("<South:price>9.95</South:price></South:book></library>");
+
+                       MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml.ToString ()));
+                       document = new XmlDocument ();
+                       document.Load (memoryStream);
+                       XmlNodeList bookList = document.GetElementsByTagName ("book", "http://www.foo.com");
+                       AssertEquals ("GetElementsByTagName (string, uri) returned incorrect count.", 1, bookList.Count);
+               }
+
                public void TestOuterXmlWithNamespace ()
                {
                        XmlElement element = document.CreateElement ("foo", "bar", "#foo");