Getting "<kml:..." everywhere, updating a Kml file
- by Rafe Lavelle
I'm reading in a Kml file, changing the placemarks' names, and saving it again.
var KmlFile = XDocument.Load("C:\\Inetpub\\wwwroot\\GeotagService\\Kml\\Photographs.kml");
XNamespace KmlNamespace = "http://www.opengis.net/kml/2.2";
// find the Placemarks in the Photos folder
IEnumerable<XElement> Placemarks = KmlFile.Element(KmlNamespace + "kml").Element(KmlNamespace + "Document").Element(KmlNamespace + "Folder").Elements(KmlNamespace + "Placemark");
foreach (XElement p in Placemarks){
p.Element(KmlNamespace + "name").Value = "testing";
}
KmlFile.Save("C:\\Inetpub\\wwwroot\\GeotagService\\Kml\\Photographs.kml");
When I save it however, every element is prefixed with <kml:, like this:
<kml:Folder>
<kml:name>Photos</kml:name>
<kml:open>1</kml:open>
<kml:Placemark>
<kml:name>testing</kml:name>
<kml:LookAt>
<kml:longitude>-10.02717694938161</kml:longitude>
<kml:latitude>53.48672543547379</kml:latitude>
<kml:altitude>0</kml:altitude>
</kml:LookAt>
<kml:styleUrl>#msn_ylw-pushpin1</kml:styleUrl>
<kml:Point>
<kml:coordinates>-10.02867619360582,53.48651240326751,0</kml:coordinates>
</kml:Point>
</kml:Placemark>...
Tomalak's comment on this question about blank xmlns gives me a clue that it might be inconsistencies between the namespaces of the document and the elements, but I can't see how I'm doing that. Anyone know?