Matt Hunter <xrkune@tconl.com>.
svn path=/trunk/mcs/; revision=6885
+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
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)
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)
{
+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>
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 ()
{
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");