Sep 16, 2014 at 6:26 AM
Edited Sep 16, 2014 at 6:39 AM
If I load a kml file that was saved from Google Earth.
KmlFile kml = KmlFile.Load(filename)
and save this kml file with
I get a prefix (kml:) in every tag of the
resulted kml file.
This appears to happen because of the namespaces in the kml file.
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2"
Note that the default namespace name the kml name space have the same Uri. This does seem
to be a problem of the XmlWriter as I tested with just an XmlWriter and got the same result. How can I get around this? Is it possible to remove the xmlns:kml namespace when the file is loaded?
Sep 16, 2014 at 7:03 PM
You might be able to remove the prefix from the
, via the
method, however, the property is currently internal so you will either need to modify the source code or get it via reflection.
Recently I added the
method to the
class, which adds a namespace and prefix, perhaps another method would help to remove a prefix?
Let me know if that doesn't work and I'll take a more detailed look,
RemoveNamespace did the job, I tested by modifying the source to make my life a little easier as below.
public void RemoveNamespacePrefix(string prefix)
if (prefix == null)
throw new ArgumentNullException("prefix");
if ((prefix == string.Empty) ||
(prefix == "xml") ||
(prefix == "xmlns"))
throw new ArgumentException("Invalid prefix.", "prefix");
string uri = this.Namespaces.LookupNamespace(prefix);
if (uri != null)
So now I can read in a file, modify it, perform a RemoveNamespacePrefix("kml") and then save it. Although I've lost the kml namespace generated by Google Earth it is still a valid kml file that can be read by any other application that needs it.