Reputation: 1
I am developer of Windows phone 7, and I want to ask: if I go to .xml code, and there is such
<?xml version="1.0" encoding="utf-8"?>
<artists>
<images>
<image size="1">http://userserve-ak.last.fm/serve/34/17666215.jpg</image>
<image size="2">http://userserve-ak.last.fm/serve/64/17666215.jpg</image>
</images>
</artists>
So how can I choose the second element there?
Upvotes: 0
Views: 234
Reputation: 46
I understand that you want to parse this XML file and get the second element value, so you can do that using something like this:
XDocument xmlDocument = XDocument.Parse("path_to_xml_file");
//you can also pass a the content as a string or a stream reader
XElement image = (from element in xmlDocument.Element("artists").Element("images").Descendants("image")
where element.Attribute("size").Value == "2"
select element).FirstOrDefault();
System.Diagnostics.Debug.WriteLine(image.Value);
Then add this imports:
using System.Linq;
using System.Xml.Linq;
And add a reference to System.Xml.Linq.dll to your project.
I think this link can also be helpful for you: How to Get XML Node from XDocument
Upvotes: 1