parsing xml files

W

Wade G

How do I use XmlDocument class to parse an xml file such
as the following - note the key issue is the number of
<stuff> elements is not fixed so if I use m_nodelist =
m_xmld.SelectNodes("/start/level/stuff") to process the
nodes they all run together and I can't separate them by
the <level> that they are at because the number of times
they appear at each level is not fixed:

<start>
<level>
<stuff>
<firstthing>foo</firstthing>
<nextthing>boo</nextthing>
<stuff>
<stuff>
<firstthing>foo</firstthing>
<nextthing>boo</nextthing>
<stuff>
<level>
<level>
<stuff>
<firstthing>blue</firstthing>
<nextthing>goo</nextthing>
</stuff>
</level
</start>
 
J

Jay B. Harlow [MVP - Outlook]

Wade,
Have you considered using two loops/lists?

One loop/list to process Level, then a second nested loop/list to process
stuff?

m_layerList = m_xmld.SelectNodes("/start/level")

m_stuffList = m_layerList.SelectNodes("stuff")

Hope this helps
Jay
 
W

Wade G

Yes, thanks. This is what I was trying to do but had the
syntax off slightly. I got it to work this morning -
note you need to use the node not the list to get the
inner node list. Here it is:

levellist = m_xmld.SelectNodes("/start/level")
For Each levelnode In levellist
stufflist = levelnode.SelectNodes("stuff")
For Each stuffnode In stufflist
'process the value
Next
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top