Hi, I have the following code that reads an XML file and pulls out attributes for a specific node to a listview control, which works as expected. I am now trying to also pull out specific node data <Words> and <Segments> from under the <Total> element and add to the listview. I was wondering, do I need to run separate loops on the XML, one to get the attributes and one to get the <Words> and <Segments> data.
Here is the code
Here is a sample of the XML
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:xsi=" xsi:noNamespaceSchemaLocation="AnalysisReport.xsd">
<Analysis Date="20150219T184601Z">
<Project SourceLang="en-us">
<Totals>
<TMs>
<TM Type="Fg" Name="Main-Power" MemoryID="Z1">
<CharsPerWord>5.75</CharsPerWord>
<Total>
<Characters>92</Characters>
<Words>16</Words>
<Segments>6</Segments>
<MeteredWords>16</MeteredWords>
</Total>
</TM>
<TM Type="Bg" Name="Minor-Power" MemoryID="9815562">
<CharsPerWord>4.63</CharsPerWord>
<Total>
<Characters>176</Characters>
<Words>38</Words>
<Segments>19</Segments>
<MeteredWords>38</MeteredWords>
</Total>
</TM>
</TMs>
</Totals>
</Project>
</Analysis>
</Report>
From what I have seen on the net, there are many different ways to read XML files and pull out specific data and to be honest, it seems a bit daunting on how to pull out the data I need.
I would appreciate any help with this.
Thanks
Here is the code
Code:
Dim loadDoc As New System.Xml.XmlDocument()
loadDoc.Load("C:\test\analysis.xml")
For Each ipNode As System.Xml.XmlNode In loadDoc.SelectNodes("/Report/Analysis/Project/Totals/TMs/TM")
Dim item As ListViewItem = ListView1.Items.Add(ipNode.Attributes("Type").InnerText)
item.SubItems.Add(ipNode.Attributes("Name").InnerText)
item.SubItems.Add(ipNode.Attributes("MemoryID").InnerText)
Next
Here is a sample of the XML
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:xsi=" xsi:noNamespaceSchemaLocation="AnalysisReport.xsd">
<Analysis Date="20150219T184601Z">
<Project SourceLang="en-us">
<Totals>
<TMs>
<TM Type="Fg" Name="Main-Power" MemoryID="Z1">
<CharsPerWord>5.75</CharsPerWord>
<Total>
<Characters>92</Characters>
<Words>16</Words>
<Segments>6</Segments>
<MeteredWords>16</MeteredWords>
</Total>
</TM>
<TM Type="Bg" Name="Minor-Power" MemoryID="9815562">
<CharsPerWord>4.63</CharsPerWord>
<Total>
<Characters>176</Characters>
<Words>38</Words>
<Segments>19</Segments>
<MeteredWords>38</MeteredWords>
</Total>
</TM>
</TMs>
</Totals>
</Project>
</Analysis>
</Report>
From what I have seen on the net, there are many different ways to read XML files and pull out specific data and to be honest, it seems a bit daunting on how to pull out the data I need.
I would appreciate any help with this.
Thanks