+2002-08-19 Jason Diamond <jason@injektilo.org>
+
+ * XmlDocument.cs, XmlElement.cs: Added implementation of
+ GetElementsByTagName courtesy of Matt Hunter <xrkune@tconl.com>.
+
2002-08-16 Jason Diamond <jason@injektilo.org>
* XmlElement.cs: Fixed writing out qualified elements courtesy of
using System.Text;
using System.Xml.XPath;
using System.Diagnostics;
+using System.Collections;
namespace System.Xml
{
throw new NotImplementedException ();
}
- [MonoTODO]
public virtual XmlNodeList GetElementsByTagName (string name)
{
- throw new NotImplementedException ();
+ ArrayList nodeArrayList = new ArrayList ();
+ this.searchNodesRecursively (this, name, nodeArrayList);
+ return new XmlNodeArrayList (nodeArrayList);
+ }
+
+ private void searchNodesRecursively (XmlNode argNode, string argName, ArrayList argArrayList)
+ {
+ XmlNodeList xmlNodeList = argNode.ChildNodes;
+ foreach (XmlNode node in xmlNodeList){
+ if (node.Name.Equals (argName))
+ argArrayList.Add (node);
+ else
+ this.searchNodesRecursively (node, argName, argArrayList);
+ }
}
[MonoTODO]
throw new NotImplementedException ();
}
- [MonoTODO]
public virtual void Load (Stream inStream)
{
- throw new NotImplementedException ();
+ XmlReader xmlReader = new XmlTextReader (inStream);
+ Load (xmlReader);
}
public virtual void Load (string filename)
//
using System;
+using System.Collections;
namespace System.Xml
{
return attributeNode != null ? attributeNode as XmlAttribute : null;
}
- [MonoTODO]
public virtual XmlNodeList GetElementsByTagName (string name)
{
- throw new NotImplementedException ();
+ ArrayList nodeArrayList = new ArrayList ();
+ this.searchNodesRecursively (this, name, nodeArrayList);
+ return new XmlNodeArrayList (nodeArrayList);
+ }
+
+ private void searchNodesRecursively (XmlNode argNode, string argName, ArrayList argArrayList)
+ {
+ XmlNodeList xmlNodeList = argNode.ChildNodes;
+ foreach (XmlNode node in xmlNodeList){
+ if (node.Name.Equals (argName))
+ argArrayList.Add (node);
+ else
+ this.searchNodesRecursively (node, argName, argArrayList);
+ }
}
[MonoTODO]
+2002-08-19 Jason Diamond <jason@injektilo.org>
+
+ * XmlDocument.cs, XmlElement.cs: Added tests for
+ GetElementsByTagName courtesy of Matt Hunter <xrkune@tconl.com>.
+
2002-08-17 Jason Diamond <jason@injektilo.org>
* XPathNavigatorMatchesTests.cs: Added tests for absolute patterns
using System;
using System.Collections;
using System.Xml;
+using System.IO;
+using System.Text;
using NUnit.Framework;
catch (Exception) {}
AssertEquals (1, element.ChildNodes.Count);
}
+
+ public void TestGetElementsByTagNameNoNameSpace ()
+ {
+ string xml = @"<library><book><title>XML Fun</title><author>John Doe</author>
+ <price>34.95</price></book><book><title>Bear and the Dragon</title>
+ <author>Tom Clancy</author><price>6.95</price></book><book>
+ <title>Bourne Identity</title><author>Robert Ludlum</author>
+ <price>9.95</price></book><Fluffer><Nutter><book>
+ <title>Bourne Ultimatum</title><author>Robert Ludlum</author>
+ <price>9.95</price></book></Nutter></Fluffer></library>";
+
+ MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml));
+ document = new XmlDocument ();
+ document.Load (memoryStream);
+ XmlNodeList bookList = document.GetElementsByTagName ("book");
+ AssertEquals ("GetElementsByTagName (string) returned incorrect count.", 4, bookList.Count);
+ }
+
public void TestInnerAndOuterXml ()
{
AssertEquals (document.InnerXml, document.OuterXml);
}
+ public void TestLoadWithSystemIOStream ()
+ {
+ string xml = @"<library><book><title>XML Fun</title><author>John Doe</author>
+ <price>34.95</price></book><book><title>Bear and the Dragon</title>
+ <author>Tom Clancy</author><price>6.95</price></book><book>
+ <title>Bourne Identity</title><author>Robert Ludlum</author>
+ <price>9.95</price></book><Fluffer><Nutter><book>
+ <title>Bourne Ultimatum</title><author>Robert Ludlum</author>
+ <price>9.95</price></book></Nutter></Fluffer></library>";
+
+ MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml));
+ document = new XmlDocument ();
+ document.Load (memoryStream);
+ AssertEquals ("Not Loaded From IOStream", true, document.HasChildNodes);
+ }
+
public void TestLoadXmlCDATA ()
{
document.LoadXml ("<foo><![CDATA[bar]]></foo>");
using System;
using System.Xml;
+using System.IO;
+using System.Text;
using NUnit.Framework;
AssertEquals ("val2", element.GetAttribute ("attr2"));
}
+ public void TestGetElementsByTagNameNoNameSpace ()
+ {
+ string xml = @"<library><book><title>XML Fun</title><author>John Doe</author>
+ <price>34.95</price></book><book><title>Bear and the Dragon</title>
+ <author>Tom Clancy</author><price>6.95</price></book><book>
+ <title>Bourne Identity</title><author>Robert Ludlum</author>
+ <price>9.95</price></book><Fluffer><Nutter><book>
+ <title>Bourne Ultimatum</title><author>Robert Ludlum</author>
+ <price>9.95</price></book></Nutter></Fluffer></library>";
+
+ MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml));
+ document = new XmlDocument ();
+ document.Load (memoryStream);
+ XmlNodeList bookList = document.GetElementsByTagName ("book");
+ AssertEquals ("GetElementsByTagName (string) returned incorrect count.", 4, bookList.Count);
+ }
+
public void TestOuterXmlWithNamespace ()
{
XmlElement element = document.CreateElement ("foo", "bar", "#foo");