XML : How to remove element from XML

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&amp;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 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 elments. So the tag Placemark becomes kml:Placemark

How may I get it right? Thanks

David

No comments:

Post a Comment