Re: [2005] Reading from xml
Don't use an XmlDocument if you just want to read XML data. It is the least efficient way to access XML. The advantage it offers is that it offers read/write, random access to the XML data. You'd only use it when that's what you need. If all you want to do is read the data from top to bottom then the most efficient way, and therefore the correct way, is to use an XmlDataReader.
I don't have time to post more than that for the moment but I suggest that you investigate the class and see what you can come with until I get back or someone else provides more info.
Re: [2005] Reading from xml
Thanks for the reply.
Well i will be writing to an xml file at some point in the project aswell. I am basically creating a little game, so i will need to read the data in, use it and update it within the program and the write (or update if thats possible) an xml file following the exact same layout.
But i will investigate the xmlDataReader to see what that offers me, but if someone could post a little bit of code to help me along, it will be greatly appreciated.
Thanks again. :afrog:
Re: [2005] Reading from xml
Re: [2005] Reading from xml
XSD.exe is a cool tool you can use to auto generate a schema from a XML file. With the schema you can create a strongly typed data set, which I think is what you're going for. The following assumes you've put your data in c:\myfile.xml
1. Open the visual studio command prompt
2. Enter xsd.exe C:\myfile.xml /outputdir:C:\
3. Right click your project, select Add > Existing Item
4. Select myfile.xsd, hit Add
5. Add the following code to your app to test it
Code:
Dim u As New Users
u.ReadXml("C:\myfile.xml")
'test
For Each drUser As Users.UserRow In u.User
Console.WriteLine("<<<<New User>>>>")
Console.WriteLine(drUser.Name)
Console.WriteLine(drUser.Occupation)
Console.WriteLine(drUser.OverallPercentage)
For Each drActivity As Users.ActivityRow In drUser.GetActivityRows
Console.WriteLine(drActivity.ActivityName)
Console.WriteLine(drActivity.ActivityLevel)
Console.WriteLine(drActivity.RightAnswers)
Console.WriteLine(drActivity.WrongAnswers)
Console.WriteLine(drActivity.PercentRight)
Next
Next
Re: [2005] Reading from xml
Hi there,
Thanks for the reply but is there any chance you could explain how that works as i may have to explain the process to a lecturer if he asks? Also what process would i use when i came to write to xml after i have used the information i have gotten out of the previous xml?
Or if anybody has any code using the xmldatareader or xmldocument method as i understand how that works and will have no problem explaining to my lecturer if needed.
Thanks again
:afrog:
Re: [2005] Reading from xml
Writing is easy, should be
Code:
u.ReadXml("C:\myfile.xml")
All your doing is using a microsoft tool to create a strongly typed dataset based on an XML file you created. The advantages of using a strongly typed dataset, in my opinion, is intellisense through the IDE, and all type converstion is done for you. So with a strongly typed dataset you can use rather than
Code:
drUser.Item("Name").ToString