I have a XML file that stores information about an application I am trying to read and it looks like this:
- <Data>
<Login UserName="Username" Password="Password"/>
-
<Application Name="AppName1" Key="Key1" Owner="Owner1"/>
-
<Application Name="AppName2" Key="Key2" Owner="Owner2"/>
-
<Application Name="AppName4" Key="Key3" Owner="Owner3"/>
-
<Owner Name="Owner1"/>
-
<Owner Name="Owner2"/>
-
<Owner Name="Owner3"/> </Data>
After all of the applications are put in I want a list of the owners stored separately like that are. I have my program write it and it works fine but when I try to read from the XML file I get the applications but the separate owners list doesn't read at all. Here is my code that I have:
- Dim x As Integer
Dim z As Integer
'//Declare XML Reader -
Dim Reader As New XmlDocument()
-
Reader.Load("ProData.xml")
'//Try reading Applications
Try
-
-
'//Read Application Element
-
Dim nods As XmlNodeList = Reader.SelectNodes("//Application")
-
For Each nod As XmlNode In nods
'//Redim Arrays
-
ReDim Preserve AppName(2)
-
ReDim Preserve AppKey(2)
-
ReDim Preserve AppOwner(2)
-
-
'//Set AppName/AppKey/AppOwner
-
AppName(x) = nod.Attributes("Name").Value
-
AppKey(x) = nod.Attributes("Key").Value
-
AppOwner(x) = nod.Attributes("Owner").Value
-
-
'//Add to index
-
x += 1
-
appcount += 1
-
cmbList.Items.Add(AppName(x))
Next nod
-
-
Catch ex As Exception
-
-
End Try
-
-
'//Try reading Owners
-
Try
-
'//Read Owner Element
-
Dim OwnerNods As XmlNodeList = Reader.SelectNodes("/Data/Owner")
-
For Each nod As XmlNode In OwnerNods
-
-
ReDim Preserve OwnLst(2)
-
'//Set Owners
-
OwnLst(z) = nod.Attributes("Name").Value
-
-
'//Add to index
-
z += 1
Next nod
-
Catch ex As Exception
End Try