Help reading an XML file

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I would like to read through a XML document but I am unfamiliar with the XMLDocument and the XDocument classes. I would appreciate a little advice on how to do this using Visual Basic 2010.
Here is what I would like to do. in my main procedure I want to open the file and read all the "top" level nodes. Believe it or not, this i where I am stuck. I can open the file. But when I try to read Elements, I get all the elements and not just the top
elements.
Here is my code.
<pre class="prettyprint Dim document As XDocument = XDocument.Load("M:mpdillonRed Cheetahexport_specs.xml")
For Each curElement As XElement In document...<redcheetah>
For Each curDesc As XElement In curElement.Descendants
MsgBox(curDesc.Name.ToString)
Next
Next[/code]
What would be the correct code to get just the direct children of the node redcheetah?
These nodes are:address, customer, user, cost-center, customer-purchase-order, credit memo, order, quote and purchase-order.

The second part of my question has to do with reading all the child elements of a parent and detecting when all those elements have been read. For example: Once I determined by the above code that I was on the "cost-center" node, I want to read all of its
elements and stop once all the elements have been read.
I have been trying to use the above code unsuccessfully to do that.
The example XML file I am trying to read can be found in the link below. It is 17 KB.
http://www.easyware.com/computer/Alpha/export_specs.xml" target="_blank XML sample

Thanks for you assistance.
pat
<br/>

View the full article
 

Similar threads

Back
Top