title: How do you save DOM Document in Java?
body: <p>I am using <code>DOM</code> parser and <code>XPATH</code> to parse a my <code>XML</code> file. I have changed a value of a node in the <code>Document Object</code>. However when I open my <code>XML</code> file, it doesn't show me any reflection. My <code>DOM</code> parser code is as below :</p>
  
  <pre><code>private void setPortNumber(int portNumber) {
          try {
          Document parsedDocument = parseDocument(tempPath + "/apache-6/conf/server.xml");
          XPath xPath = XPathFactory.newInstance().newXPath();
          XPathExpression expr;
          expr = (XPathExpression) xPath.compile("//Connector");
          Object result = expr.evaluate(parsedDocument, XPathConstants.NODESET);
          NodeList nodes = (NodeList) result;
          for (int i = 0; i &lt; nodes.getLength(); i++) {
              Node node =nodes.item(i);
              NamedNodeMap attributes = node.getAttributes();
              for(int j=0; j&lt; attributes.getLength(); j++){
                  String value = attributes.item(j).getNodeValue();
                  if(value.equals("HTTP/1.1")){
                      Node valueNode = attributes.item(0);
                      valueNode.setNodeValue(portNumber+"");
                  }
              }
          }
          } catch (XPathExpressionException e) {}
      }
      private Document parseDocument(String xmPath) {
          Document doc = null;
          try {
              DocumentBuilderFactory domFactory = 
                  DocumentBuilderFactory.newInstance();
              DocumentBuilder builder;
  
              builder = domFactory.newDocumentBuilder();
  
              doc = builder.parse(xmPath);
          }catch (Exception e) {}
          return doc;
      }
  </code></pre>
  
  <p>How can I save my document after done with changes?</p>
  
  <p>Can anyone help me to resolve this?</p>