parsing xml files

  • Thread starter Thread starter Wade G
  • Start date Start date
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>
 
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
 
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
 
Back
Top