title: How to properly create custom XML elements?
body: <p>I'm recently working on a Weather Application that I want to save every customer search in an .xml formatted file. <a href="https://i.stack.imgur.com/JaQVA.png" rel="nofollow noreferrer">. . See GUI Design Here . .</a></p>
  
  <p>I'm using the following code on Java to write the needed elements on the .xml file but the issue is that I cannot append the next search and save a new search as shown below : </p>
  
  <pre><code>&lt;search&gt;...NEW ELEMENTS (NEW SEARCH)...&lt;/seach&gt;
  </code></pre>
  
  <p>when i click the "ForeCast" Button.</p>
  
  <p>WeatherParser.java :</p>
  
  <pre><code>public void writeOnXML(String date, String[] term, String found, String geoNameID){
  
      try {
          XMLOutputFactory xMLOutputFactory = XMLOutputFactory.newFactory();
          XMLStreamWriter xMLStreamWriter;
          xMLStreamWriter = xMLOutputFactory
              .createXMLStreamWriter(new FileOutputStream
                  ("src\\main\\java\\stax\\weatherSearches.xml"));
          //Create &lt;weatherSearches&gt;&lt;/weatherSearches&gt; (in weatherSearches.xml)
          xMLStreamWriter.writeStartElement("weathersearches");
  
              //Create &lt;search&gt;&lt;/search&gt; (weatherSearches.xml)
              xMLStreamWriter.writeStartElement("search");
              xMLStreamWriter.writeAttribute("date", date);
  
                  //Create &lt;search&gt;&lt;term&gt;...&lt;/term&gt;&lt;/search&gt; (weatherSearches.xml)
                  xMLStreamWriter.writeStartElement("term");
                      xMLStreamWriter.writeStartElement("temperature");
                      xMLStreamWriter.writeCharacters(term[0]);
                      xMLStreamWriter.writeEndElement(); //Close &lt;Temperature&gt;
                      xMLStreamWriter.writeStartElement("windDirection");
                      xMLStreamWriter.writeCharacters(term[1]);
                      xMLStreamWriter.writeEndElement(); //Close &lt;WindDirection&gt;
                      xMLStreamWriter.writeStartElement("windSpeed");
                      xMLStreamWriter.writeCharacters(term[2]);
                      xMLStreamWriter.writeEndElement(); //Close &lt;WindSpeed&gt;
                      xMLStreamWriter.writeStartElement("humidity");
                      xMLStreamWriter.writeCharacters(term[3]);
                      xMLStreamWriter.writeEndElement(); //Close &lt;Humidity&gt;
                      xMLStreamWriter.writeStartElement("pressure");
                      xMLStreamWriter.writeCharacters(term[4]);
                      xMLStreamWriter.writeEndElement(); //Close &lt;Pressure&gt;
                      xMLStreamWriter.writeStartElement("visibility");
                      xMLStreamWriter.writeCharacters(term[5]);
                      xMLStreamWriter.writeEndElement(); //Close &lt;Visibility&gt;
                  xMLStreamWriter.writeEndElement(); //close &lt;term&gt;
  
                  //Create &lt;search&gt;&lt;found&gt;&lt;/found&gt;&lt;/search&gt; (weatherSearches.xml)
                  xMLStreamWriter.writeStartElement("found");
                  xMLStreamWriter.writeCharacters(found);
                  xMLStreamWriter.writeEndElement(); //Close &lt;found&gt;
  
                  //Create &lt;search&gt;&lt;geoNameID&gt;&lt;/geoNameID&gt;&lt;/search&gt; (weatherSearches.xml)
                  xMLStreamWriter.writeStartElement("geoNameID");
                  xMLStreamWriter.writeCharacters(geoNameID);
                  xMLStreamWriter.writeEndElement(); //Close &lt;geoNameID&gt;
  
              //Create &lt;search&gt;&lt;/search&gt; (weatherSearches.xml)
              xMLStreamWriter.writeEndElement(); //Close &lt;search&gt;
  
          xMLStreamWriter.writeEndElement(); //Close &lt;weathersearches&gt;
  
          //xMLStreamWriter.flush();;
          xMLStreamWriter.close();
  
      } 
      catch (FileNotFoundException ex) {
          loadErrorException(ex);
      } 
      catch (XMLStreamException ex) {
          loadErrorException(ex);
      }       
  }
  </code></pre>
  
  <hr>
  
  <p>weatherSearches.xml :</p>
  
  <pre><code>&lt;weathersearches&gt;
  &lt;search date="Saturday - 14:00"&gt;
      &lt;term&gt;
          &lt;temperature&gt;11�C (52�F)&lt;/temperature&gt;
          &lt;windDirection&gt;Southerly&lt;/windDirection&gt;
          &lt;windSpeed&gt;18mph&lt;/windSpeed&gt;
          &lt;humidity&gt;97%&lt;/humidity&gt;
          &lt;pressure&gt;988mb&lt;/pressure&gt;
          &lt;visibility&gt;Poor&lt;/visibility&gt;
      &lt;/term&gt;
      &lt;found&gt;true&lt;/found&gt;
      &lt;geoNameID&gt;2656397&lt;/geoNameID&gt;
  &lt;/search&gt;
  &lt;/weathersearches&gt;
  </code></pre>
  
  <p>Also will the unknown symbol in the element <code>&lt;weathersearches&gt;&lt;search&gt;&lt;term&gt;&lt;temperature&gt;</code> will cause me any errors or should I remove it from there?</p>