Solved

vb.net -> Reading xml file

Posted on 2014-02-12
4
447 Views
Last Modified: 2014-02-28
Hi,

I have the following in an XML file (Please see below) and i would like to pull these stats

home":{"name":"Arka Gdynia","score":"0"}
"away":{"name":"Stomil Olsztyn","score":"0",
"timeElapsed":63


[{"eventTypeId":1,"eventId":27144224,"score":{"home":{"name":"Arka Gdynia","score":"0","games":"","sets":""},"away":{"name":"Stomil Olsztyn","score":"0","games":"","sets":""}},"timeElapsed":63,"fullTimeElapsed":{"hour":0,"min":0,"sec":0},"status":"SecondHalfKickOff","matchStatus":"SecondHalfKickOff"},{"eventTypeId":1,"eventId":27147134,"score":{"home":{"name":"Qalali Club","score":"1","games":"","sets":""},"away":{"name":"Al Tadamun Buri","score":"0","games":"","sets":""}},"timeElapsed":42,"fullTimeElapsed":{"hour":0,"min":0,"sec":0},"status":"KickOff","matchStatus":"KickOff"},{"eventTypeId":1,"eventId":27147133,"score":{"home":{"name":"Al Ahli","score":"0","games":"","sets":""},"away":{"name":"Al Bahrain SC","score":"0","games":"","sets":""}},"timeElapsed":42,"fullTimeElapsed":{"hour":0,"min":0,"sec":0},"status":"KickOff","matchStatus":"KickOff"},{"eventTypeId":1,"eventId":27147141,"score":{"home":{"name":"La Union CF","score":"0","games":"","sets":""},"away":{"name":"FC Nordsjaelland","score":"1","games":"","sets":""}},"timeElapsed":40,"fullTimeElapsed":{"hour":0,"min":0,"sec":0},"status":"KickOff","matchStatus":"KickOff"},{"eventTypeId":1,"eventId":27147416,"score":{"home":{"name":"Dinamo Moscow","score":"2","games":"","sets":""},"away":{"name":"Dnipro","score":"0","games":"","sets":""}},"timeElapsed":44,"fullTimeElapsed":{"hour":0,"min":0,"sec":0},"status":"KickOff","matchStatus":"KickOff"}]

Open in new window

0
Comment
Question by:runnerjp2005
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39853599
That's JSON. Where is the XML?
0
 

Author Comment

by:runnerjp2005
ID: 39853618
Sorry my bad

<ScoresResponse xmlns="http://www.betfair.com/servicetypes/v1/InPlay/" debug="true">
<script id="FirebugLite" firebugIgnore="true" extension="Chrome"/>
<EventState>
<eventId>27144224</eventId>
<eventTypeId>1</eventTypeId>
<fullTimeElapsed>
<hour>0</hour>
<min>0</min>
<sec>0</sec>
</fullTimeElapsed>
<matchStatus>SecondHalfKickOff</matchStatus>
<status>SecondHalfKickOff</status>
<score>
<away>
<gameSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<games/>
<name>Stomil Olsztyn</name>
<score>0</score>
<sets/>
</away>
<home>
<gameSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<games/>
<name>Arka Gdynia</name>
<score>0</score>
<sets/>
</home>
</score>
<timeElapsed>77</timeElapsed>
</EventState>
<EventState>
<eventId>27147134</eventId>
<eventTypeId>1</eventTypeId>
<fullTimeElapsed>
<hour>0</hour>
<min>0</min>
<sec>0</sec>
</fullTimeElapsed>
<matchStatus>KickOff</matchStatus>
<status>KickOff</status>
<score>
<away>
<gameSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<games/>
<name>Al Tadamun Buri</name>
<score>1</score>
<sets/>
</away>
<home>
<gameSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<games/>
<name>Qalali Club</name>
<score>1</score>
<sets/>
</home>
</score>
<timeElapsed>46</timeElapsed>
</EventState>
<EventState>
<eventId>27147133</eventId>
<eventTypeId>1</eventTypeId>
<fullTimeElapsed>
<hour>0</hour>
<min>0</min>
<sec>0</sec>
</fullTimeElapsed>
<matchStatus>FirstHalfEnd</matchStatus>
<status>FirstHalfEnd</status>
<score>
<away>
<gameSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<games/>
<name>Al Bahrain SC</name>
<score>0</score>
<sets/>
</away>
<home>
<gameSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<games/>
<name>Al Ahli</name>
<score>0</score>
<sets/>
</home>
</score>
<timeElapsed>48</timeElapsed>
</EventState>
<EventState>
<eventId>27147141</eventId>
<eventTypeId>1</eventTypeId>
<fullTimeElapsed>
<hour>0</hour>
<min>0</min>
<sec>0</sec>
</fullTimeElapsed>
<matchStatus>FirstHalfEnd</matchStatus>
<status>FirstHalfEnd</status>
<score>
<away>
<gameSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<games/>
<name>FC Nordsjaelland</name>
<score>1</score>
<sets/>
</away>
<home>
<gameSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<games/>
<name>La Union CF</name>
<score>0</score>
<sets/>
</home>
</score>
<timeElapsed>46</timeElapsed>
</EventState>
<EventState>
<eventId>27147416</eventId>
<eventTypeId>1</eventTypeId>
<fullTimeElapsed>
<hour>0</hour>
<min>0</min>
<sec>0</sec>
</fullTimeElapsed>
<matchStatus>SecondHalfKickOff</matchStatus>
<status>SecondHalfKickOff</status>
<score>
<away>
<gameSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<games/>
<name>Dnipro</name>
<score>0</score>
<sets/>
</away>
<home>
<gameSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<games/>
<name>Dinamo Moscow</name>
<score>2</score>
<sets/>
</home>
</score>
<timeElapsed>46</timeElapsed>
</EventState>
</ScoresResponse>

Open in new window

0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 39853619
There are multiple ways of reading XML files. Check following

http://www.codeproject.com/Articles/4826/XML-File-Parsing-in-VB-NET
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 250 total points
ID: 39854043
Hi runnerjp2005;

The following Linq to XML will return the needed information from the document.

' Load the XML document
Dim xdoc As XDocument = XDocument.Load("C:/Working Directory/ScoresResponse.xml")
' Get reference to root node
Dim xRoot As XElement = xdoc.Root
' Get the Namespace being used in the document
Dim ns As XNamespace = xRoot.Name.Namespace

' Query the document for the needed information.
Dim results = From es In xRoot.Descendants(ns + "EventState") _
              Select New With _
              { _
                  .HomeName = es.Element(ns + "score").Element(ns + "home").Element(ns + "name").Value, _
                  .HomeScore = es.Element(ns + "score").Element(ns + "home").Element(ns + "score").Value, _
                  .AwayName = es.Element(ns + "score").Element(ns + "away").Element(ns + "name").Value, _
                  .AwayScore = es.Element(ns + "score").Element(ns + "away").Element(ns + "score").Value, _
                  .TimeElapsed = es.Element(ns + "timeElapsed").Value _
              }

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now