Hello Ventuzians!
THE FORUMS ARE CLOSED!

Please join our discord server HERE!! << click me :D

We are shutting our Ventuz Forum, but don't worry, it will all be archived for you to search in if you have a query. From now on, please add all your comments, questions or observations into our Discord Server

Thanks for the great time - see you on discord!!
Dee, Karol, Daniel and the whoooole Product and Support team!

Accessing XML from C# Script

Q and A about functionality and how to solve a special task for your application.

Moderator: Support

Post Reply
Tobistobi

Accessing XML from C# Script

Post by Tobistobi » 22 Jan 2014, 19:10

Hey, anyone can help on how to access data in an XML file via C# scripting ––– the task is too complex using the XML nodes (which work generally well) …

Let's assume this test XML file that I would drop into C:\ root folder:

<?xml version="1.0" encoding="utf-8"?>
<DataBody DocumentCode="GL0000000" Serial="133603" Time="180351265" Venue="PDC" Date="20131204" FeedFlag="P" LogicalDate="20131204" DocumentType="DT_PINGS" Version="249" >
<Event Code="OWG2014">
<EventStandings DateTime="2013-12-04T18:03:51+04:00" LastEvent="FSX030000" TotalEvents="302" FinishedEvents="23">
<PingTable>
<PingLine Rank="1" SortRank="1" RankEqual="N" RankTotal="3" SortRankTotal="3" RankTotalEqual="Y" Organisation="SUI">
<PingNumber Type="M" Go="1" Si="0" Br="0" Total="1" />
<PingNumber Type="W" Go="3" Si="2" Br="1" Total="6" />
<PingNumber Type="X" Go="0" Si="0" Br="0" Total="0" />
<PingNumber Type="TOT" Go="4" Si="2" Br="1" Total="7" />
</PingLine>
<PingLine Rank="2" SortRank="2" RankEqual="N" RankTotal="3" SortRankTotal="4" RankTotalEqual="Y" Organisation="ITA">
<PingNumber Type="M" Go="3" Si="1" Br="0" Total="4" />
<PingNumber Type="W" Go="1" Si="0" Br="2" Total="3" />
<PingNumber Type="X" Go="0" Sir="0" Br="0" Total="0" />
<PingNumber Type="TOT" Go="4" Si="1" Br="2" Total="7" />
</PingLine>
<PingLine Rank="3" SortRank="3" RankEqual="N" RankTotal="7" SortRankTotal="7" RankTotalEqual="Y" Organisation="JPN">
<PingNumber Type="M" Go="0" Si="0" Br="1" Total="1" />
<PingNumber Type="W" Go="3" Si="0" Br="0" Total="3" />
<PingNumber Type="X" Go="0" Si="0" Br="0" Total="0" />
<PingNumber Type="TOT" Go="3" Si="0" Br="1" Total="4" />
</PingLine>
</PingTable>
</EventStandings>
</Event>
</DataBody>


what I tried is to get a Rank Info into this.Tester based on SortRank (here for Sort Rank = "3") … doing so would make it easy for me to know how all the other things I need would work, but didn't get past that step until now. My approach (which does not work):

using System.Xml; // is added to the top section

// code snippet as used in the function
XmlDocument xmlDoc = new XmlDocument(); // creates the XML Object
xmlDoc.Load(@"C:\Pingcount.xml"); // load the XML document named Pingcount.xml at C:\

XmlNode readnode;
readnode = xmlDoc.SelectSingleNode(@"/DataBody/Event/EventStandings/PingTable/PingLine[@SortRank='3']/@Rank");
string _loadedText = readnode.InnerText;

this.Tester = _loadedText;
changed = true;
return false;

Has anybody an idea how to do that? Help would be much appreciated …
.tobi.

Christian Krix Schmidt
Posts: 290
Joined: 18 Jan 2012, 11:36
Location: Dubai, United Arab Emirates
Contact:

Re: Accessing XML from C# Script

Post by Christian Krix Schmidt » 23 Jan 2014, 11:39

I did a lot of XML in C# to create dynamic content pages. In order to speed up the whole thing and having an easier life I read out the relevant XML data and stored it in arrays in the script. That let's you pretty much do anything you want without having to deal with the XML side of things all the time.

Post Reply