all groups > dotnet xml > december 2004 >
You're in the

dotnet xml

group:

Read xml file with multiple elements



Read xml file with multiple elements Mark
12/31/2004 10:46:35 AM
dotnet xml: I have the following xml file that I want to read in using vb.net 2003:

<dordivision name="district 1" propname="District 1">

<printer id="location11" duplex="false">Location 11</printer>

<printer id="location12" duplex="true">Location 12</printer>

<printer id="location13" duplex="true">Location 13</printer>

<printer id="location14" duplex="false">Location 14</printer>

</dordivision>

<dordivision name="district 2" propname="District 2">

<printer id="location21" duplex="true">Location 21</printer>

<printer id="location22" duplex="true">Location 22</printer>

</dordivision>

<dordivision name="district 3" propname="District 3">

<printer id="location31" duplex="true">Location 31</printer>

<printer id="location32" duplex="true">Location 32</printer>

<printer id="location33" duplex="true">Location 33</printer>

<printer id="location34" duplex="true">Location 34</printer>

</dordivision>

I have been able to get the names into a combobox from the dordivision
element. I would like to be able to have the user select the item from the
combobox that they want and then have the form change and display each
printer name in a list of radio buttons. This will vary from 1 to many
elements. Is this possible to do? For some reason I only get one printer.

Re: Read xml file with multiple elements Dino Chiesa [Microsoft]
1/3/2005 12:29:38 PM
off the top of my head, Could be 2 problems :
1. not reading the XML properly or successfully
2. improper data binding


So, how are you getting the XML into a data structure? Serialization?
something else?
With serialization I can read in that data pretty simply like so:

Dim xmlS1 As New XmlSerializer(GetType(Info))

' de-serialize (read)
Dim path As String
path="printers.xml"
Dim r As StreamReader
r= File.OpenText(path)
Dim data as Info
data = xmlS1.Deserialize(r)
r.Close()


where Info is a type generated from xsd.exe. [To get this type, wrap your
XML in an <Info> element, then run these 2 commands in succession:
xsd.exe printers.xml
xsd.exe /language:vb /c printers.xsd

]

After reading in the XML, it becomes an issue of data binding.
Can you show us some code?

-Dino



[quoted text, click to view]

AddThis Social Bookmark Button