Thomas1029 Level: Trainee
 Registered: 09-02-2011 Posts: 2
|
Visual Basic 2010 - XML - Looping through childnodes
This is an excert of the XML file I'm working with:
<?xml version="1.0" encoding="utf-8" ?>
- <!-- TestData.xml stores hardware and software configuration information from the Win32 Classes of the WMI root\CIMV2 namespace
-->
- <root>
- <class Name="Win32_DiskDrive">
- <instance Name="\\.\PHYSICALDRIVE0">
<properties BytesPerSector="510" FirmwareRevision="3.AHG" InterfaceType="IDE" Model="ST3320820AS ATA Device" Partitions="1" SCSIPort="1" SectorsPerTrack="63" />
</instance>
- <instance Name="\\.\PHYSICALDRIVE1">
<properties BytesPerSector="511" FirmwareRevision="8.01" InterfaceType="IDE" Model="ST380013A ATA Device" Partitions="2" SCSIPort="0" SectorsPerTrack="63" />
</instance>
- <instance Name="\\.\PHYSICALDRIVE2">
<properties BytesPerSector="512" FirmwareRevision="8.11" InterfaceType="IDE" Model="ST380013A ATA Device" Partitions="2" SCSIPort="0" SectorsPerTrack="63" />
</instance>
</class>
</root>
I'm tring to loop through each instance node ("\\.\PHYSICALDRIVE0", "\\.\PHYSICALDRIVE1" and "\\.\PHYSICALDRIVE2") and return the properties of these instances.
The .FirstChild line dose return the first property (BytesPerSector) but I can seem to read the remaining properties.
Below is a copy of my code:
Dim sClass As String = "Win32_DiskDrive"
Dim XMLFile As String = "C:\Temp\XML\TestData.xml"
Dim xmlDoc As New XmlDocument
xmlDoc.Load(XMLFile)
Dim node As XmlNode = xmlDoc.SelectSingleNode("/root/class[@Name='" & sClass & "']")
If node IsNot Nothing Then
For Each sInstance As XmlNode In node.ChildNodes
For i As Integer = 0 To sInstance.Attributes.Count - 1
Dim CurrentInstance As XmlAttribute = sInstance.Attributes.Item(i)
Console.WriteLine(CurrentInstance.Value)
For Each sProperty As XmlNode In node.FirstChild
Dim CurrentProperty As XmlAttribute = sProperty.Attributes.Item(0)
Console.WriteLine(CurrentProperty.Name)
Console.WriteLine(CurrentProperty.Value)
Dim nextNode As XmlNode = CurrentProperty.NextSibling
For p As Integer = 0 To nextNode.Attributes.Count - 1
Dim NextProperty As XmlAttribute = sProperty.Attributes.Item(p)
Console.WriteLine(NextProperty.Name)
Console.WriteLine(NextProperty.Value)
Next
Next
Next
Next
End If
Thanks in advance for any help I can get on this issue.
Thomas Traylor
|