title: How to append a child element to a large XML file using Java?
body: <p>I am trying to create a XML file, using Java, that is a collection of GPS coordinates (GPX).  Every time I receive a coordinate from my android device (approximately 1 every second)  I need to append the results to an existing XML file.  The output that I am looking for is shown below with the trkpt element as the repeated item.  The problem is that I can't just add the new trkpt to the end of the file because it needs to be inside the trkseg parent element.</p>
  
  <p>So far I have tried two different APIs, SIMPLEXML and JDOM.  With SIMPLEXML I couldn't figure out how to append a child element to an existing file so I switched to JDOM.  JDOM allowed me to append the trkpt element as shown below, but as the file started growing it quickly slowed down the user interface of the program.  With JDOM I was using the SAXBuilder to reopen the file and append.  I think the issue with this was that it had to reproduce the entire file in memory before it added the new element and rewrote the file.  So the larger the file got the more demanding the operation was on the device.  I need a solution that doesn't examine/copy the entire file before writing the new data.  Is there a more efficient way to accomplish this with Java or an API for Java?  Thanks for any help!</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;gpx xmlns="http://www.topografix.com/GPX/1/1"&gt;
          &lt;trk&gt;
              &lt;trkseg&gt;
                  &lt;trkpt lon="9.860624216140083" lat="54.9328621088893"&gt;
                      &lt;ele&gt;228.0&lt;/ele&gt;
                  &lt;/trkpt&gt;
                  &lt;trkpt lon="9.860624216140100" lat="54.9328621088754"&gt;
                      &lt;ele&gt;234.0&lt;/ele&gt;
                  &lt;/trkpt&gt;
                  &lt;trkpt lon="9.860624216140343" lat="54.9328621088678"&gt;
                      &lt;ele&gt;227.0&lt;/ele&gt;
                  &lt;/trkpt&gt;
              &lt;/trkseg&gt;
          &lt;/trk&gt;
  &lt;/gpx&gt;
  </code></pre>