Iterating XML Data (Take two)

  • Thread starter Thread starter NachoShaw
  • Start date Start date
N

NachoShaw

Guest
Hi

For those who graciously offer help to us less knowledgeable users in order for us continue our learning, i appreciate any advice you may give. This is a take two thread, the last was got tainted by attitude so apologies if this appears to be a double thread, i doubt anyone will reply to the previous one..


My question is in 2 parts. Part one is asking the current method of what i am trying to do, Part two is whether i am approaching this in the right way.

Part 1

I have an XML file that i need to extract data from. Most of the nodes are unique and generated by an application. Because the node names are unique, i need as method that will simply return all nodes names & node values because i am entering both names & values directly into a document. I do have the names of the 3 main elements that contain the nodes. These names are

  • revision
  • generalInfo
  • pressureInfo

The code i have been trying so far is

xml_doc.Load(loadedXMLdocAsPath)
Dim revisionNodeList As XmlNodeList = xml_doc.GetElementsByTagName("revision")
For Each node1 As XmlNode In revisionNodeList
Debug.Print(node1.Name & " - " & node1.Value)
Next

Dim generalNodeList As XmlNodeList = xml_doc.GetElementsByTagName("generalInfo")
For Each node2 As XmlNode In generalNodeList
Debug.Print(node2.Name & " - " & node2.Value)
Next

Dim pressureNodeList As XmlNodeList = xml_doc.GetElementsByTagName("pressureInfo")
For Each node3 As XmlNode In pressureNodeList
Debug.Print(node3.Name & " - " & node3.Value)
Next

'expected returns per node
nodeName01 - Some unique value
nodeName02 - Some other unique value
'etc etc


First, this doesnt return any results. I was expecting or rather hoping that i could get the node.Name & node.Value for each Node in the interation but thats not the case. Secondly, i realise there are 3 separate iterations happening in a large xml file and so would look for a more simplified / less iterative method of getting the nodes for the elements which leads into Part 2

Part 2

In the example above, there are 3 iterations. Is there a method that would allow me to collect the node data for all 3 elements but only in a single document iteration or can it be only done per element?

Is the multiple iteration method the best way of getting the node data or is there another way? I thought that maybe i could iterate the xml document once into a datatable then get the data that way using SQL but i can also see level problems and also search issues on collecting the specific data further down the line.

Thats it, my 2 part question laid out in the best way i can describe it without anyone being offended.


Any help greatly appreciated


Thanks



Nacho is the derivative of Nigel - True fact! I am self taught in VB.Net. 50% of the time, I am right 100% of the time!

Continue reading...
 
Back
Top