preventing unnecessary namespace into xml

Wessdottemy

New Member
Im working on a project that modifies a kml file by adding gps coordinates on a specific spot in the kml. My code, however, is adding the "gx" namespace on ALL of the elements when its saved at the end. I have researched and looked at a ton of different Visual Basic XML writing methods and I've ran out of ideas. How do I stop unnecessary namespaces to be added?!test.kml:\[code\]<?xml version="1.0" encoding="utf-8" standalone="yes"?><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.opengis.net/kml/2.2"> <Document> <name>test.kml</name> <Snippet>File Created Mon Jul 9 15:50:16 2012</Snippet> <Style id="multiTrack_n"> <IconStyle> <Icon> <href>http://maps.google.com/mapfiles/kml/shapes/track.png</href> </Icon> </IconStyle> <LineStyle> <color>99ffac59</color> <width>6</width> </LineStyle> </Style> <Folder> <Placemark> <name>test.kml</name> <styleUrl>#multiTrack_n</styleUrl> <gx:Track> <!--GPS Tracking data Points--> </gx:Track> </Placemark> </Folder> </Document></kml>\[/code\]Code:\[code\]Imports System.IOImports System.XmlImports System.DateTimeImports <xmlns="http://www.opengis.net/kml/2.2">Imports <xmlns:gx="http://www.opengis.net/kml/2.2">...Public Sub addCoordinate(ByVal lon As Double, ByVal lat As Double, ByVal att As Double, ByVal timeStamp As String) Dim currentDoc = XDocument.Load("test.kml") Try whenElement = _ <when><%= timeStamp %></when> coordElement = _ <gx:coord><%= lon.ToString %>,<%= lat.ToString %>,<%= att.ToString %></gx:coord> Dim testLocation = currentDoc.<kml>.<Document>.<Folder>.<Placemark>.Elements.Last() testLocation.Add(whenElement) testlocation.Add(coordElement) currentDoc.Save("test.kml") Catch ex As Exception Console.WriteLine(ex) End Try End Sub\[/code\]after code:\[code\]<?xml version="1.0" encoding="utf-8" standalone="yes"?><gx:kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.opengis.net/kml/2.2"> <gx:Document> <gx:name>test.kml</gx:name> <gx:Snippet>File Created Mon Jul 9 16:40:11 2012</gx:Snippet> <gx:Style id="multiTrack_n"> <gx:IconStyle> <gx:Icon> <gx:href>http://maps.google.com/mapfiles/kml/shapes/track.png</gx:href> </gx:Icon> </gx:IconStyle> <gx:LineStyle> <gx:color>99ffac59</gx:color> <gx:width>6</gx:width> </gx:LineStyle> </gx:Style> <gx:Folder> <gx:name>test.kml</gx:name> <gx:Placemark> <gx:name>test</gx:name> <gx:styleUrl>#multiTrack_n</gx:styleUrl> <gx:Track> <!--GPS Tracking data Points--> <when xmlns="http://www.opengis.net/kml/2.2">2012-07-09T08:40:29Z</when> <gx:coord xmlns:gx="http://www.opengis.net/kml/2.2">0,0,0</gx:coord> <when xmlns="http://www.opengis.net/kml/2.2">2012-07-09T08:40:33Z</when> <gx:coord xmlns:gx="http://www.opengis.net/kml/2.2">0,0,0</gx:coord> <when xmlns="http://www.opengis.net/kml/2.2">2012-07-09T08:40:41Z</when> <gx:coord xmlns:gx="http://www.opengis.net/kml/2.2">0,0,0</gx:coord> </gx:Track> </gx:Placemark> </gx:Folder> </gx:Document></gx:kml>\[/code\]
 
Back
Top