How to find specific value of the node in xml file
Posted
by
user2735149
on Stack Overflow
See other posts from Stack Overflow
or by user2735149
Published on 2013-10-31T09:50:23Z
Indexed on
2013/10/31
9:53 UTC
Read the original article
Hit count: 240
I am making windows phone 8 app based the webservices. This is my xml code:
- <response>
<timestamp>2013-10-31T08:30:56Z</timestamp>
<resultsOffset>0</resultsOffset>
<status>success</status>
<resultsLimit>8</resultsLimit>
<resultsCount>38</resultsCount>
- <headlines>
- <headlinesItem>
<headline>City edge past Toon</headline>
<keywords />
<lastModified>2013-10-30T23:45:22Z</lastModified>
<audio />
<premium>false</premium>
+ <links>
- <api>
- <news>
<href>http://api.espn.com/v1/sports/news/1600444?region=GB</href>
</news>
</api>
- <web>
<href>http://espnfc.com/uk/en/report/381799/city-edge-toon?ex_cid=espnapi_public</href>
</web>
- <mobile>
<href>http://m.espn.go.com/soccer/gamecast?gameId=381799&lang=EN&ex_cid=espnapi_public</href>
</mobile>
</links>
<type>snReport</type>
<related />
<id>1600444</id>
<story>Alvardo Negredo and Edin Dzeko struck in extra-time to book Manchester City's place in the last eight of the Capital One Cup, while Costel Pantilimon kept a clean sheet in the 2-0 win to keep the pressure on Joe Hart. </story>
<linkText>Newcastle 0-2 Man City</linkText>
- <images>
- <imagesItem>
<height>360</height>
<alt>Man City celebrate after Edin Dzeko scored their second extra-time goal at Newcastle.</alt>
<width>640</width>
<name>Man City celeb Edin Dzeko goal v nufc 20131030 [640x360]</name>
<caption>Man City celebrate after Edin Dzeko scored their second extra-time goal at Newcastle.</caption>
<type>inline</type>
<url>http://espnfc.com/design05/images/2013/1030/mancitycelebedindzekogoalvnufc20131030_640x360.jpg</url>
</imagesItem>
</images>
Code behind:
myData = XDocument.Parse(e.Result, LoadOptions.None);
var data = myData.Descendants("headlines").FirstOrDefault();
var data1 = from query in myData.Descendants("headlinesItem")
select new UpdataNews
{
News = (string)query.Element("headline").Value,
Desc = (string)query.Element("description"),
Newsurl = (string)query.Element("links").Element("mobile").Element("href"),
Imageurl=(string)query.Element("images").Element("imagesItem").Element("url").Value,
};
lstShow.ItemsSource = data1;
I am trying to get value from xml tags and assign them to News,Desc, etc. Everything works fine except Imageurl, it shows NullException. I tried same method for Imageurl, i dont know whats going wrong. Help..
© Stack Overflow or respective owner