title: Convert JavaScript object (array) to XML
body: <p>I have JavaScript object which is formatted as JSON using this code:</p>
  
  <pre><code>obj.push({      
      lat: (lat / 1e5).toFixed(5),
      lon: (lon / 1e5).toFixed(5),
      ele: "0"
  });
  </code></pre>
  
  <p>This object/array can contain potentially hundereds of indiviual objects/properties which look like this:</p>
  
  <pre><code> [{"lat":"32.71883","lon":"-16.76118","ele":"0"},{"lat":"32.71882","lon":"-16.76138","ele":"0"},{"lat":"32.71881","lon":"-16.76159","ele":"0"},{"lat":"32.71880","lon":"-16.76179","ele":"0"},{"lat":"32.71879","lon":"-16.76199","ele":"0"},{"lat":"32.71878","lon":"-16.76220","ele":"0"}....]
  </code></pre>
  
  <p>I'd like to convert this object to XML using the correct element tags in the following format:</p>
  
  <pre><code>&lt;trkpt lat="32.7188300" lon="-16.7611800"&gt;   // note how this lumps together two separate properties into a single element
   &lt;ele&gt;0&lt;/ele&gt;
  &lt;/trkpt&gt;
  </code></pre>
  
  <p>I've found a snippet of code to tranform the object: </p>
  
  <pre><code>function objectToXml(object) {
          var xml = '';
          for (var prop in object) {
              if (!object.hasOwnProperty(prop)) {
                  continue;
              }
              if (object[prop] == undefined)
                  continue;
              xml += "&lt;" + prop + "&gt;";
              if (typeof object[prop] == "object")
                  xml += objectToXml(new Object(object[prop]));
              else
                  xml += object[prop];
              xml += "&lt;!--" + prop + "--\&gt;";
          }
          return xml;
      }
  </code></pre>
  
  <p>This certainly converts the object to some extent, however, it tries to create a key for each property set, an concatenates the properties into one string. </p>
  
  <pre><code>  &lt;0&gt;32.71883-16.761180&lt;1&gt;32.71882-16.761380&lt;2&gt;32.71881-16.761590&lt;3&gt;32.71880-16.761790&lt;4&gt;.....
  </code></pre>
  
  <p>Any suggestions on how I can use this function to correctly format the XML as described?</p>