title: Java XML modifying
body: <pre><code>import java.io.ByteArrayInputStream;
  import java.io.IOException;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.ParserConfigurationException;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  import org.xml.sax.SAXException;
  
  public class modifyXML {
  
      public static void modify(StringBuffer XMLBuffer) throws IOException, ParserConfigurationException, SAXException{
  
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder db = dbf.newDocumentBuilder();   
          Document doc = db.parse(new ByteArrayInputStream(XMLBuffer.toString().getBytes()));
          Element rootNode = doc.getDocumentElement();
  
          NodeList priceList = rootNode.getElementsByTagName("price");
          priceList.item(0).setTextContent("190");
  
          NodeList inStockList = rootNode.getElementsByTagName("id_product_attribute");
          inStockList.item(0).setTextContent("100");
  
  
  
      }
  }
  </code></pre>
  
  <p>I am trying to modify an XML file and then put it all back together. I have managed with the modifying part, but I can not get the XML file back together. The result can be either a String or a StringBuffer. </p>
  
  <p>What is the best/easiest way to do this?</p>