Thursday, 19 February 2015

Why can't I read this XML values with XElement?



This is the XML:



<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://ift.tt/Wr35qg">
<Document>
<LookAt>
<longitude>51.84750492</longitude>
<latitude>61.85536484</latitude>
<range>4423610</range>
</LookAt>
<Style id="Filled_Label">
</Style>
</Document>
</kml>


And this is the code:



XElement doc = XElement.Load(UiUtils.GetABSPath + "/kml/MyFile2.kml");
XNamespace ns = XNamespace.Get("http://ift.tt/1Erz9zx");

var query = from x in doc.Elements(ns + "longitude")
select x;

Response.Write(query.Count());

foreach (XElement item in query)
{
Response.Write(item.Value);
}


but it does print nothing (0 elements). Where am I wrong?


No comments:

Post a Comment