title: Java Transformer outputs &lt; and &gt; instead of <>
body: <p>I am editing an XML file in Java with a Transformer by adding more nodes. The old XML code is unchanged but the new XML nodes have <code>&amp;lt;</code> and <code>&amp;gt;</code> instead of &lt;> and are on the same line. How do I get &lt;> instead of <code>&amp;lt;</code> and <code>&amp;gt;</code> and how do I get line breaks after the new nodes. I already read several similar threads but wasn't able to get the right formatting. Here is the relevant portion of the code:</p>
  
  <pre><code>// Read the XML file
  
  DocumentBuilderFactory dbf= DocumentBuilderFactory.newInstance();   
  DocumentBuilder db = dbf.newDocumentBuilder();   
  Document doc=db.parse(xmlFile.getAbsoluteFile());
  Element root = doc.getDocumentElement();
  
  
  // create a new node
  Element newNode = doc.createElement("Item");
  
  // add it to the root node
  root.appendChild(newNode);
  
  // create a new attribute
  Attr attribute = doc.createAttribute("Name");
  
  // assign the attribute a value
  attribute.setValue("Test...");
  
  // add the attribute to the new node
  newNode.setAttributeNode(attribute);
  
  
  
  // transform the XML
  Transformer transformer = TransformerFactory.newInstance().newTransformer();   
  transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 
  transformer.setOutputProperty(OutputKeys.METHOD, "xml");
  StreamResult result = new StreamResult(new FileWriter(xmlFile.getAbsoluteFile()));   
  DOMSource source = new DOMSource(doc);   
  transformer.transform(source, result);
  </code></pre>
  
  <p>Thanks</p>