Tags

,

Very often you will need to parse xml files to get information so why not use dataset to have a oo view.
If you have a xml file, you can use XML tool like XMLSpy to generate a schema .xsd file or write a simple code

Dim MyDS As DataSet = New DataSet()
MyDS.ReadXml(“test.xml”)

MyDS.WriteXmlSchema(“C:\Temp\test.xds”)

then in visual studio command line use xsd to generate class
xsd.exe -c -l:vb -n:XmlSerializationOXI temp.xsd

add both schema and class file to your project. Now you can load XML to your Dataset

Dim ds As New DataSet()
‘ Load the schema into the DataSet
ds.ReadXmlSchema(“temp.xsd”)

‘ Load the data into the data document
Dim XDocStudents As New XmlDataDocument(ds)
XDocStudents.Load(“C:\Temp\temp.xml”)

Console.WriteLine(ds.Tables(0).Rows.Count)

Advertisements