|
-
May 22nd, 2006, 01:12 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Help Reading DataSet from XML
I have the following XML file:
Code:
<map gsid="101">
<name> Dalian Plant </name>
<briefing locid="LOADINGSCREEN_MAPDESCRIPTION_dalianplant">map description for modders maps not localized (english only)</briefing>
<music> common/sound/menu/music/load_CH_music.ogg </music>
<modes>
<mode type="gpm_cq">
<maptype ai="1" players="16" type="doubleassault" locid="GAMEMODE_DESCRIPTION_doubleassault">Unlocalized test for this mode on this map</maptype>
<maptype players="32" type="headon" locid="GAMEMODE_DESCRIPTION_headon">Unlocalized test for this mode on this map</maptype>
<maptype players="64" type="headon" locid="GAMEMODE_DESCRIPTION_headon">Unlocalized test for this mode on this map</maptype>
</mode>
<mode type="gpm_coop">
<maptype ai="1" players="16" type="doubleassault" locid="GAMEMODE_DESCRIPTION_COOP_doubleassault">Unlocalized test for this mode on this map</maptype>
</mode>
</modes>
</map>
And this code:
Code:
string gpm = "";
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(MapFileName);
foreach(System.Data.DataRelation myRelation in ds.Tables["mode"].ChildRelations)
{
foreach(System.Data.DataRow myRow in ds.Tables["mode"].Rows)
{
foreach(System.Data.DataRow childrow in myRelation.ChildTable.Rows)
{
gpm = gpm + myRow["type"] + "," + childrow["players"] + "/";
}
}
}
return gpm;
I need my output to be:
"gpm_cq,16/gpm_cq,32/gpm_cq,64/gpm_coop,16"
but it's not working the way I want.
-
May 22nd, 2006, 02:07 PM
#2
Hyperactive Member
Re: Help Reading DataSet from XML
Is there a reason you are accessing an XML file through a data source?
The XML itself is fairly powerful.
Code:
XmlDocument xd = new XmlDocument();
xd.Load(@"c:\temp\vbforums.xml");
foreach (XmlElement xMode in xd.GetElementsByTagName("modes"))
{
foreach(XmlElement xMapType in xMode.GetElementsByTagName("maptype"))
{
Console.WriteLine(xMapType.GetAttribute("players"));
}
}
-
May 22nd, 2006, 02:35 PM
#3
Thread Starter
Addicted Member
Re: Help Reading DataSet from XML
Thanks. I don't need a dataset, it was just an easy way to import the xml into a grid to see if it would help me visually.
How do I reference the "gpm_cq" on the same line as your Console.Writeline?
I tried pulling up all the intellisense properties on xMode and xMapType and I'm looking through the Locals window but I haven't figured it out yet.
-
May 23rd, 2006, 01:20 AM
#4
Hyperactive Member
Re: Help Reading DataSet from XML
 Originally Posted by brandoom
Thanks. I don't need a dataset, it was just an easy way to import the xml into a grid to see if it would help me visually.
How do I reference the "gpm_cq" on the same line as your Console.Writeline?
I tried pulling up all the intellisense properties on xMode and xMapType and I'm looking through the Locals window but I haven't figured it out yet.
Code:
XmlDocument xd = new XmlDocument();
xd.Load(@"c:\temp\vbforums.xml");
foreach (XmlElement xMode in xd.GetElementsByTagName("modes"))
{
foreach(XmlElement xMapType in xMode.GetElementsByTagName("maptype"))
{
Console.WriteLine(xMapType.GetAttribute("players"));
Console.WriteLine(xMode.GetAttribute("type"));
}
}
Rate my post if it helped you.
Last edited by umilmi81; May 23rd, 2006 at 01:23 AM.
-
May 23rd, 2006, 09:41 AM
#5
Thread Starter
Addicted Member
Re: Help Reading DataSet from XML
I tried that already and it returns a blank string. Any other ideas?
-
May 23rd, 2006, 12:55 PM
#6
Hyperactive Member
Re: Help Reading DataSet from XML
 Originally Posted by brandoom
I tried that already and it returns a blank string. Any other ideas?
It should work. Remember it's case sensitive. So "type" is different from "Type" is different from "TYPE". Check your XML again.
-
May 23rd, 2006, 06:34 PM
#7
Thread Starter
Addicted Member
Re: Help Reading DataSet from XML
Sorry but it doesn't work. I know it's case sensitive.
Code:
? xMode.GetAttribute("type")
""
? xMode.GetAttribute("Type")
""
? xMode.GetAttribute("TYPE")
""
-
May 23rd, 2006, 09:42 PM
#8
Thread Starter
Addicted Member
Re: Help Reading DataSet from XML
Problem Solved.
Notice the top line needs to be "mode" NOT "modes".
Thanks for helping me out on this one. I have my head wrapped around the xml now.
Code:
foreach (XmlElement xMode in xd.GetElementsByTagName("mode"))
{
foreach(XmlElement xMapType in xMode.GetElementsByTagName("maptype"))
{
Console.WriteLine(xMapType.GetAttribute("players"));
Console.WriteLine(xMode.GetAttribute("type"));
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|