Hey guys,
I was wondering if someone could help me with getting data out of my xml file and storing it in arrays
My xml file looks as follows
and so i far i have the following code to load the xml file:Code:<?xml version="1.0" encoding="utf-8"?> <Users> <User Name="David Jones" Occupation="Student" OverallPercentage="50"> <Activity> <ActivityName>Numbers</ActivityName> <ActivityLevel>Reception</ActivityLevel> <RightAnswers>2</RightAnswers> <WrongAnswers>2</WrongAnswers> <PercentRight>50</PercentRight> </Activity> <Activity> <ActivityName>Numbers</ActivityName> <ActivityLevel>Year1</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> <Activity> <ActivityName>Numbers</ActivityName> <ActivityLevel>Year2</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> <Activity> <ActivityName>Addition</ActivityName> <ActivityLevel>Reception</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> <Activity> <ActivityName>Addition</ActivityName> <ActivityLevel>Year1</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> <Activity> <ActivityName>Addition</ActivityName> <ActivityLevel>Year2</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> </User> <User Name = "John Smith" Occupation = "Student" OverallPercentage = "0"> <Activity> <ActivityName>Numbers</ActivityName> <ActivityLevel>Reception</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> <Activity> <ActivityName>Numbers</ActivityName> <ActivityLevel>Year1</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> <Activity> <ActivityName>Numbers</ActivityName> <ActivityLevel>Year2</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> <Activity> <ActivityName>Addition</ActivityName> <ActivityLevel>Reception</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> <Activity> <ActivityName>Addition</ActivityName> <ActivityLevel>Year1</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> <Activity> <ActivityName>Addition</ActivityName> <ActivityLevel>Year2</ActivityLevel> <RightAnswers>0</RightAnswers> <WrongAnswers>0</WrongAnswers> <PercentRight>0</PercentRight> </Activity> </User> </Users>
Now what i need is for the name, occupation and overall percentage for each user to be stored in one array (which i have already set up) so that it will look as follows:Code:Dim xmlDoc As XmlDocument = New XmlDocument Dim xmlNodelist As XmlNodeList Dim xmlNode As XmlNode Dim i As Integer = 0 xmlDoc.Load(xmlFilePath) xmlNodelist = xmlDoc.SelectNodes("/Users/User")
users(0).Name = "David Jones"
users(0).Occupation = "Student"
users(0).OverallPercentage = 50
users(1).Name = "John Smith"
users(1).Occupation = "Student"
users(1).OverallPercentage = 0
and then i was all the data for the several activities to be stored in a seperate array (which again i already have declared) so that it will look as follows:
activity(0).Name = "Numbers"
activity(0).Level = "Reception"
activity(0).Right = 2
activity(0).wrong = 2
activity(0).percent = 50
activity(1).Name = "Numbers"
activity(1).Level = "Year1"
activity(1).Right = 0
activity(1).Wrong = 0
activity(1).Percent = 0
.
..
...
etc
Thanks in advance for any help offered.
![]()




Reply With Quote