title: Create XML document using nodeList
body: <p>I need to create a XML Document object using the NodeList. Can someone pls help me to do this. This is my Java code:</p>
  
  <pre><code>import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.xpath.*; 
  import org.w3c.dom.*;
  
  public class ReadFile {
  
      public static void main(String[] args) {
          String exp = "/configs/markets";
          String path = "testConfig.xml";
          try {
              Document xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(path);
              XPath xPath = XPathFactory.newInstance().newXPath();
              XPathExpression xPathExpression = xPath.compile(exp);
              NodeList nodes = (NodeList)
                xPathExpression.evaluate(xmlDocument,
                                         XPathConstants.NODESET);
  
          } catch (Exception ex) {
              ex.printStackTrace();
          } 
      }
  }
  </code></pre>
  
  <p>I want to have an XML file like this:</p>
  
  <pre><code>&lt;configs&gt;
      &lt;markets&gt;   
          &lt;market&gt;
              &lt;name&gt;Real&lt;/name&gt;
          &lt;/market&gt;
          &lt;market&gt;
              &lt;name&gt;play&lt;/name&gt;
          &lt;/market&gt;
      &lt;/markets&gt;
  &lt;/configs&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>