I have a XML file that stores information about an application I am trying to read and it looks like this:
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:
Code:
<Data>[INDENT] <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"/>[/INDENT] </Data>
Code:
Dim x As Integer[INDENT] Dim z As Integer[/INDENT] '//Declare XML Reader Dim Reader As New XmlDocument() Reader.Load("ProData.xml")[INDENT] '//Try reading Applications[/INDENT][INDENT] Try[/INDENT][INDENT][INDENT] '//Read Application Element Dim nods As XmlNodeList = Reader.SelectNodes("//Application") For Each nod As XmlNode In nods[/INDENT][/INDENT] [INDENT][INDENT][INDENT] '//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))[/INDENT][/INDENT][/INDENT][INDENT][INDENT] Next nod Catch ex As Exception End Try '//Try reading Owners Try[/INDENT][/INDENT][INDENT][INDENT][INDENT] '//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[/INDENT][/INDENT][/INDENT][INDENT][INDENT] Next nod Catch ex As Exception[/INDENT][/INDENT][INDENT] End Try[/INDENT]
Comment