Groups | Blog | Home
all groups > dotnet xml > july 2004 >

dotnet xml : Accessing the root node of an xml document


sutcliffe_grant NO[at]SPAM hotmail.com
7/13/2004 11:33:50 PM
Hi

Hopefully someone can assist me establish how to access the root node
and the first level node of an XmlDocument which I have loaded as per
the code below. So far, all I can achieve the output I need with the
root node hard and the first node coded. In the foreach I retrieve is
next child node ("Customer").
Using ChildNodes[0] fails and no other property or methods of the
object return the data I need.

private XmlDocument myDoc = new XmlDocument ();
myDoc.Load (XMLFileName);
txtWriter.WriteStartElement ("CustomersInfo"); // Hard coded
txtWriter.WriteStartElement ("Customers"); // hard coded
XmlNode nde = myDoc.ChildNodes [1];
foreach (XmlNode nd1 in nde.ChildNodes)
{
if (nd1.HasChildNodes ==true)
{
IterateNodes(nd1,txtWriter);
}
}
txtWriter.WriteFullEndElement();
txtWriter.WriteFullEndElement();
txtWriter.Flush ();
txtWriter.Close();

Thanks in advance

Oleg Tkachenko [MVP]
7/14/2004 11:45:24 AM
[quoted text, click to view]

XmlNode rootElement = myDoc.SelectSingleNode("/*");
XmlNode level1Element = myDoc.SelectSingleNode("/*/*");

--
Oleg Tkachenko [XML MVP]
AddThis Social Bookmark Button