I am relative new with windows phone so I don't know how to parse a document retrieved from the internet.
Now I am able to get it and print in it by console. I want to set each poi retrieved in an instance of my POI class which has all fields from the xml.
By this I print the xml:
XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
System.Diagnostics.Debug.WriteLine(xdoc.FirstNode.ToString());
My class POI has this fields:
Strings: name, description, thumbnal, url; Doubles: lat, lon
And my xml seems like this:
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:default="http://www.opengis.net/kml/2.2"
default:ar="http://www.openarml.org/arml/1.0"
default:wikitude="http://www.openarml.org/wikitude/1.0">
<Document>
<ar:provider xmlns:ar="http://www.openarml.org/arml/1.0"
id="myid.com">
<ar:name>Name of the owner</ar:name>
<ar:description><![CDATA[Description of the xml]]></ar:description>
<wikitude:providerUrl xmlns:wikitude="http://www.openarml.org/wikitude/1.0">www.webpage.es</wikitude:providerUrl>
<wikitude:tags xmlns:wikitude="http://www.openarml.org/wikitude/1.0">tag1,tag2,tag3,tag4</wikitude:tags>
<wikitude:logo xmlns:wikitude="http://www.openarml.org/wikitude/1.0">http://mylogourl.png</wikitude:logo>
<wikitude:icon xmlns:wikitude="http://www.openarml.org/wikitude/1.0">www.myiconurl.png</wikitude:icon></ar:provider>
<default:Placemark id="id53">
<ar:provider xmlns:ar="http://www.openarml.org/arml/1.0">myid.com</ar:provider>
<default:name>PLACE</default:name>
<default:description><![CDATA[Description of the place.]]></default:description>
<wikitude:info xmlns:wikitude="http://www.openarml.org/wikitude/1.0">
<wikitude:thumbnail>http://urltothethumbnail/</wikitude:thumbnail>
<wikitude:url>http://urltotheplace.com</wikitude:url>
</wikitude:info>
<default:Point>
<default:coordinates>-3.0000000000,43.0000000000,0</default:coordinates>
</default:Point>
</default:Placemark>
</default:Document>
</default:kml>
I have lots of placemarks (POI), all with the same fields. I want to have an array with all POI retrieved.
I tried with something like this but it says 0 using count:
var pois = xdoc.Root
.Elements("Placemark")
.Select(poi => new POI(
(String)stop.Attribute("name"),
(String)stop.Attribute("description"),
(String)stop.Attribute("thumbnail"),
(String)stop.Attribute("url"),
(Double)stop.Attribute("lat"),
(Double)stop.Attribute("lon")))
.ToList();
If I can get the id of the placemark, it would be useful. I could add another var to my POI class.
EDIT: I tried what one user said in his answer and it crash by giving an exception: System.ArgumentNullException occurred in System.Xml.Linq.ni.dll... I add the modified code:
XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
XNamespace ns = "http://www.opengis.net/kml/2.2";
var placemarks = xdoc.Root.Descendants(ns + "Placemark");
var pois = placemarks
.Select(poi => new POI(
(String)poi.Attribute("name"),
(String)poi.Attribute("description"),
(String)poi.Attribute("thumbnail"),
(String)poi.Attribute("url"),
(Double)poi.Attribute("lat"),
(Double)poi.Attribute("lon")))
.ToList();
System.Diagnostics.Debug.WriteLine(pois.Count);