BillGatesFan wrote:
Is there anyway to read a collection of xml elements in .NET? The XML
Reader class does not seem like it can do it. It reads the file
sequentially.
I want to read an xml file and get the collection of elements named
book. The for each book element I want to get its attributes and inner
element attributes.
Do you know System.Xml.XmlDocument or
System.Xml.XPath.XPathDocument/XPathNavigator? Both read the complete
XML document into a tree structure and then allow you to use XPath to
select elements. So with XmlDocument and C# you could do e.g.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("file.xml");
XmlNodeList books = xmlDoc.SelectNodes("//book");
then you can iterate over the node list and do what you need to do (e.g.
access attributes or access child elements) for each book element node.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/