X
x73
Guest
I have a very simple basic XML file that I need to read. The structure is below:
<assets>
<asset>
<Category>cat1</Category>
<Installed>Yes</Installed>
<Name>bob</Name>
</asset>
<asset>
<Category>cat1</Category>
<Installed>no</Installed>
<Name>jack</Name>
</asset>
<asset>
<Category>cat2</Category>
<Installed>Yes</Installed>
<Name>julie</Name>
</asset>
<asset>
<Category>cat3</Category>
<Installed>Yes</Installed>
<Name>linda</Name>
</asset>
<asset>
<Category>cat4</Category>
<Installed>No</Installed>
<Name>jake</Name>
</asset>
<asset>
<Category>cat5</Category>
<Installed>Yes</Installed>
<Name>paul</Name>
</asset>
I have 5 group boxes on a form. Each groupbox corresponds to a category, information in cat1 will be placed in groupbox1 and cat2 will be placed in groupbox2, etc.. I have a label which is either green for yes and red for no. A textbox is used to display the name information. The label and textbox are created dynamically as the xml file is being read.
This is what I am attempting which is not working very well as I have never worked with XML files before.
Dim xmlr = XmlReader.Create("c:\temp\test.xml")
Do While xmlr.Read()
If xmlr.NodeType = XmlNodeType.Element AndAlso xmlr.Name = "Category" Then
MessageBox.Show(xmlr.ReadElementString)
MessageBox.Show(xmlr.ReadElementString)
Else
xmlr.Read()
End If
Loop
The messagebox.show function is there as a test to see if the file is being read.. I plan on replacing them with a series of if … then statements to place the dynamic label and textbox and populate them with the data..
ie.
if xmlr.nodetype = element and name of element = "category1" then place label and textbox in groupbox1
if xmlr.nodetype = element and name of element = "category2" then place label and textbox in groupbox2..
Where am I going wrong?? Please help..
Jason
Continue reading...
<assets>
<asset>
<Category>cat1</Category>
<Installed>Yes</Installed>
<Name>bob</Name>
</asset>
<asset>
<Category>cat1</Category>
<Installed>no</Installed>
<Name>jack</Name>
</asset>
<asset>
<Category>cat2</Category>
<Installed>Yes</Installed>
<Name>julie</Name>
</asset>
<asset>
<Category>cat3</Category>
<Installed>Yes</Installed>
<Name>linda</Name>
</asset>
<asset>
<Category>cat4</Category>
<Installed>No</Installed>
<Name>jake</Name>
</asset>
<asset>
<Category>cat5</Category>
<Installed>Yes</Installed>
<Name>paul</Name>
</asset>
I have 5 group boxes on a form. Each groupbox corresponds to a category, information in cat1 will be placed in groupbox1 and cat2 will be placed in groupbox2, etc.. I have a label which is either green for yes and red for no. A textbox is used to display the name information. The label and textbox are created dynamically as the xml file is being read.
This is what I am attempting which is not working very well as I have never worked with XML files before.
Dim xmlr = XmlReader.Create("c:\temp\test.xml")
Do While xmlr.Read()
If xmlr.NodeType = XmlNodeType.Element AndAlso xmlr.Name = "Category" Then
MessageBox.Show(xmlr.ReadElementString)
MessageBox.Show(xmlr.ReadElementString)
Else
xmlr.Read()
End If
Loop
The messagebox.show function is there as a test to see if the file is being read.. I plan on replacing them with a series of if … then statements to place the dynamic label and textbox and populate them with the data..
ie.
if xmlr.nodetype = element and name of element = "category1" then place label and textbox in groupbox1
if xmlr.nodetype = element and name of element = "category2" then place label and textbox in groupbox2..
Where am I going wrong?? Please help..
Jason
Continue reading...