Obtain specific values in XML nodes

Joined
Dec 15, 2010
Messages
5
Programming Experience
1-3
I'm hoping someone can help with a problem I'm having getting multiple values out of an XML node. I'm trying to use vb.net to read a sydi xml document and write the requested information to excel. the XML portion I'm having issues with is this
<computer>
- <storage>
- <drives name="SCSI Disk" deviceid="\\.\PHYSICALDRIVE0" interface="SCSI" totaldisksize="67.34">
<partition name="C:" size="67.83" freespace="57.16" filesystem="NTFS" />
</drives>
- <drives name="SCSI Disk Device" deviceid="\\.\PHYSICALDRIVE1" interface="SCSI" totaldisksize="136.73">
<partition name="D:" size="136.72" freespace="96.41" filesystem="NTFS" />
</drives>
</storage>
<computer>

The problem is whenever I run the following code it will only give me the last one entered so in this case the D partition information will be listed but not the C. I believe it has to be with the fact I need a for each statement in there but I can't seem to figure out the right code.

VB.NET:
Dim reader As XmlTextReader = New XmlTextReader("C:\sydi\myXML.xml")
        If File.Exists("C:\sydi\myXML.xml") Then
            Do While (reader.Read())
                    Select reader.NodeType
                    Case XmlNodeType.Element 'Display beginning of element.
                        If reader.Name = "partition" Then
                            If reader.HasAttributes Then 'If attributes exist
                                While reader.MoveToNextAttribute()
                                    If reader.Name = "freespace" Then
                                        excelSheet.Cells(Xval, Yval).Value = reader.Value
                                    End If
                                End While
                            End If
                        End If
 
Back
Top