Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8212181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:40:21+00:00 2026-06-07T10:40:21+00:00

Im working on a project that modifies a kml file by adding gps coordinates

  • 0

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:

<?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:

Imports System.IO
Imports System.Xml
Imports System.DateTime
Imports <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

after 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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:40:23+00:00Added an answer on June 7, 2026 at 10:40 am

    After realizing what said in the comments, I realized if I have the Default NS in the XML as http://www.opengis.net/kml/2.2, every element is assumed to have it, so when I re-save, it applies the namespaces.

    Something so small and simple…Silly me… learn something everyday

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project that downloads a zip file and unzips locally. The
I am working on an Eclipse plugin that modifies Java code in a user's
I'm working on a project that has file uploads. These files are given a
I have a working project that Im amending, it crashes after trying to use
I'm working on project that lets users choose some scientific authors and columnists and
Im working on a project that has an implementation of JOSSO in place. We
I'm working on a project that requires to convert html email into text. Below
I'm working on a project that is trying to use context-free grammars for parsing
I am working on a project that already has begun being developed. ON some
I'm working in a project that need to get SVD (Single Values Decomposition) for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.