I do have the following xml file
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<open>1</open>
<Placemark>
<name>L14A</name>
<description>ID:01F40BF0
PLACEMENT:Home Woods
RSSI:-82
</description>
<Style>
<IconStyle>
<Icon>
<href>http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=3|0000CC|FFFFFF</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>-73.16551208,44.71051217,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
The file is bigger than that but it does represent the structure. I'm trying to remove the element <Style>
but I can't find a way to get it right.
I have tried the following method: How to remove an element from an xml using Xdocument when we have multiple elements with same name but different attributes
The code is:
XDocument xdoc = XDocument.Load("kkk.kml");
xdoc.Descendants("Style").Remove();
xdoc.Save("kkk-mod.kml");
The Descendants collection is always empty.
Also, when I save the file, it does append "kml:" to each of my elements (see below).
<kml:Placemark>
<kml:name>L14A</kml:name>
<kml:description>ID:01F40BF0
</kml:description>
<kml:Point>
<kml:coordinates>-73.200,44.500,0</kml:coordinates>
</kml:Point>
</kml:Placemark>
How may I get it right?
- the remove
- the :kml appended in the final file.