title: Java DOM XML Parser - printed XML contains one tag instead of multiple ones
body: <p>I have written some code loading records from MySQL and parsing them and saving into XML file. What I wanted to achieve was somethin like this:</p>
  
  <pre><code>&lt;part&gt;&lt;row&gt;.....&lt;/row&gt;&lt;row&gt;...&lt;/row&gt;&lt;/part&gt;
  </code></pre>
  
  <p>Now I have:</p>
  
  <pre><code>&lt;part&gt;&lt;row&gt;...&lt;/row&gt;&lt;/part&gt;
  </code></pre>
  
  <p>Here is screen showing my poroblem:</p>
  
  <p><a href="https://i.stack.imgur.com/aDEJE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aDEJE.jpg" alt="enter image description here"></a></p>
  
  <p>Here is Java code section which parses data into XML <code>Document</code> structure:</p>
  
  <pre><code>private void callSPInParOrWithout(final Document doc, 
              final Connection conn) {
          ResultSet rs = null;
          CallableStatement cs = null;
          try {
              // &lt;part&gt;
              Element part = doc.createElement("part");
              doc.appendChild(part);
  
              cs = conn.prepareCall("{CALL getBrandRows(?)}");
              cs.setString(1, "Brand#13");
  
              boolean results = cs.execute();
              while (results) {
                  // &lt;row&gt;
                  Element row = doc.createElement("row");
                  part.appendChild(row);   
                  rs = cs.getResultSet();
                  while (rs.next()) {
                      // &lt;p_partkey&gt;
                      Element pPartKey = doc.createElement("p_partkey");
                      pPartKey.appendChild(doc.createTextNode(Integer.toString(
                              rs.getInt("p_partkey"))));
                      row.appendChild(pPartKey);
                      // &lt;p_name&gt;
                      Element pName = doc.createElement("p_name");
                      pName.appendChild(doc.createTextNode(rs.getString(
                              "p_name")));
                      row.appendChild(pName);
                      // &lt;p_mfgr&gt;   
                      Element pMfgr = doc.createElement("p_mfgr");
                      pMfgr.appendChild(doc.createTextNode(rs.getString(
                              "p_mfgr")));
                      row.appendChild(pMfgr);
                      // &lt;p_brand&gt;
                      Element pBrand = doc.createElement("p_brand");
                      pBrand.appendChild(doc.createTextNode(rs.getString(
                              "p_brand")));
                      row.appendChild(pBrand);
                      // &lt;p_type&gt;
                      Element pType = doc.createElement("p_type");
                      pType.appendChild(doc.createTextNode(rs.getString(
                              "p_type")));
                      row.appendChild(pType);
                      // &lt;p_size&gt;
                      Element pSize = doc.createElement("p_size");
                      pSize.appendChild(doc.createTextNode(Integer.toString(
                              rs.getInt("p_size"))));
                      row.appendChild(pSize);
                      // &lt;p_container&gt;
                      Element pContainer = doc.createElement("p_container");
                      pContainer.appendChild(doc.createTextNode(rs.getString(
                              "p_container")));
                      row.appendChild(pContainer);
                      // &lt;p_retailprice&gt;
                      Element pRetailPrice = doc.createElement("p_retailprice");
                      pRetailPrice.appendChild(doc.createTextNode(
                              Float.toString(rs.getFloat("p_retailprice"))));
                      // &lt;p_comment&gt;
                      Element pComment = doc.createElement("p_comment");
                      pComment.appendChild(doc.createTextNode(rs.getString(
                              "p_comment")));
                      row.appendChild(pComment);
                  }
                  results = cs.getMoreResults();
              }
          } catch (SQLException e) {
              JOptionPane.showMessageDialog(null, e.getMessage(), 
                      "Exception occured", JOptionPane.ERROR_MESSAGE);
          } finally {
              try {
                  if (rs != null) rs.close();
                  if (cs != null) cs.close();
              } catch (SQLException e) {
              }
          }
      }
  </code></pre>
  
  <p>As you can see in the screenshot it works well but I made some mistake with creating <code>&lt;row&gt;</code> tag.</p>