title: Append child in XML document using Classic ASP
body: <p>I have the following asp-classic code which appends 3 variables into an XML document, 'location_x', 'location_y' and 'date_and_time'.</p>
  
  <p>The ASP-Classic code - creates or appends an existing XML document.</p>
  
  <pre><code>Function LoadObjecttoXML(strXMLFilePath, strFileName)
  
      Dim objDom
      Dim objGpx
      Dim objWpt
      Dim objRte
      Dim objRtept
      Dim objDateTime
      Dim objattLat
      Dim objattLon
      Dim objPI
      Dim blnFileExists
  
      'Instantiate the Microsoft XMLDOM
      Set objDom = server.CreateObject("Microsoft.XMLDOM")
      objDom.preserveWhiteSpace = True
  
      blnFileExists = objDom.Load(strXMLFilePath &amp; "\" &amp; strFileName)
  
      If blnFileExists = True Then
          Set objGpx = objDom.documentElement
      Else
          'GPX root element and append it to the XML document.
          Set objGpx = objDom.createElement("gpx")
          objDom.appendChild objGpx                                   
      End If
  
      Set objWpt = objDom.createElement("wpt")
  
          'Create "Lat" attribute'
          Set objattLat = objDom.createAttribute("lat")
          objattLat.Text = (location_x)
          objWpt.setAttributeNode objattLat
  
          'Create "Lon" attribute'
          Set objattLon = objDom.createAttribute("lon")
          objattLon.Text = (location_y)
          objWpt.setAttributeNode objattLon
  
          'Create "date_and_time" element'
          Set objDateTime = objDom.createElement("time")
          objDateTime.Text = (date_and_time)
  
      'Append "wpt" element as a child container element "gpx".'
      objGpx.appendChild objWpt
      'Append the "time" element as a child of the "wpt" element'
      objWpt.appendChild objDateTime
  
      'Append "rte" element only once'
      If blnFileExists = True Then
          Set objRte = objDom.documentElement
      Else
          Set objRte = objDom.createElement("rte")
          objGpx.appendChild objRte
      End If
  
      Set objRtept = objDom.createElement("rtept")
  
          'Create "Lat" attribute'
          Set objattLat = objDom.createAttribute("lat")
          objattLat.Text = (location_x)
          objRtept.setAttributeNode objattLat
  
          'Create "Lon" attribute'
          Set objattLon = objDom.createAttribute("lon")
          objattLon.Text = (location_y)
          objRtept.setAttributeNode objattLon
  
          'Create "date_and_time" element'
          Set objDateTime = objDom.createElement("time")
          objDateTime.Text = (date_and_time)
  
      'Append "rtept" element as a child container element "rte".'
      objRte.appendChild objRtept
      'Append the "time" element as a child of the "rtept" element'
      objRtept.appendChild objDateTime
  
      If blnFileExists = False Then
          'Create the xml processing instruction - and append to XML file
          Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
          objDom.insertBefore objPI, objDom.childNodes(0)
      End If
  
      'Save the XML document.
      objDom.save strXMLFilePath &amp; "\" &amp; strFileName
  
      Set objDom = Nothing
      Set objGpx = Nothing
      Set objWpt = Nothing
      Set objRte = Nothing
      Set objRtept = Nothing
      Set objDateTime = Nothing
      Set objattLat = Nothing
      Set objattLon = Nothing
      Set objPI = Nothing
      Set blnFileExists = Nothing
  
  End Function
  
  On Error Resume Next
  
  'File path c:\
  LoadObjecttoXML "c:\Inetpub\wwwroot\xml","doc.xml"
  
  'error check
  If err.number &lt;&gt; 0 then
      Response.write("Error: " &amp; err.number )
  Else
      Response.write("Success!")
  End If
  </code></pre>
  
  <p>The problem I have is when I append the variables for a second time, the appended XML isn't placed inside the correct elements. </p>
  
  <p>For example the XML code would look something like this on the first append: </p>
  
  <pre><code>&lt;gpx&gt;
      &lt;wpt lat="52.000" lon="-1.000"&gt;
          &lt;time&gt;2016-09-23 23:38:00&lt;/time&gt;
      &lt;/wpt&gt;
      &lt;rte&gt;
          &lt;rtept lat="52.000" lon="-1.000"&gt;
              &lt;time&gt;2016-09-23 23:38:00&lt;/time&gt;
          &lt;/rtept&gt;
      &lt;/rte&gt;
  &lt;/gpx&gt; 
  </code></pre>
  
  <p>When I append for the second time:</p>
  
  <pre><code>&lt;gpx&gt;
      &lt;wpt lat="52.000" lon="-1.000"&gt;
          &lt;time&gt;2016-09-23 23:38:00&lt;/time&gt;
      &lt;/wpt&gt;
      &lt;rte&gt;
          &lt;rtept lat="52.000" lon="-1.000"&gt;
              &lt;time&gt;2016-09-23 23:38:00&lt;/time&gt;
          &lt;/rtept&gt;
      &lt;/rte&gt;
      &lt;wpt lat="52.100" lon="-1.100"&gt;
          &lt;time&gt;2016-09-23 23:39:00&lt;/time&gt;
      &lt;/wpt&gt;
      &lt;rte&gt;
          &lt;rtept lat="52.100" lon="-1.100"&gt;
              &lt;time&gt;2016-09-23 23:39:00&lt;/time&gt;
          &lt;/rtept&gt;
      &lt;/rte&gt;
  &lt;/gpx&gt; 
  </code></pre>
  
  <p>I would like the XML to append like this:</p>
  
  <pre><code>&lt;gpx&gt;
      &lt;wpt lat="52.000" lon="-1.000"&gt;
          &lt;time&gt;2016-09-23 23:38:00&lt;/time&gt;
      &lt;/wpt&gt;
      &lt;wpt lat="52.100" lon="-1.100"&gt;
          &lt;time&gt;2016-09-23 23:39:00&lt;/time&gt;
      &lt;/wpt&gt;
      &lt;rte&gt;
          &lt;rtept lat="52.000" lon="-1.000"&gt;
              &lt;time&gt;2016-09-23 23:38:00&lt;/time&gt;
          &lt;/rtept&gt;
          &lt;rtept lat="52.100" lon="-1.100"&gt;
              &lt;time&gt;2016-09-23 23:39:00&lt;/time&gt;
          &lt;/rtept&gt;
      &lt;/rte&gt;
  &lt;/gpx&gt;
  </code></pre>
  
  <p>I'd love to hear of any suggestions; hints or tips, on how I could achieve this.  </p>