# XML Zeilenumbruch im Header



## PcWichtel (5. Feb 2014)

Sehr geehrte Programmierer!
Ich probiere gerade eine XML - Datei zu erstellen und hätte gerne in der ersten Zeile ein Zeilenumbruch!

<?xml version="1.0" encoding="ISO-8859-15"?><test>
<Staff id="1">
<firstname>Tim</firstname>
</Staff>
</test>

Es wird bis jetzt so angezeigt! Hätte aber gerne <test> in die zweite Zeile!

Hier mal soweit der Code:

```
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
 
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
 
public class Creator {
 
	public static void main(String argv[]) {
 
	  try {
 
		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
		
		// root elements
		Document doc = docBuilder.newDocument();
		doc.setXmlStandalone(true);
		Element rootElement = doc.createElement("test");
		doc.appendChild(rootElement);
		
	
		
		// staff elements \r\n
		Element staff = doc.createElement("Staff");
		rootElement.appendChild(staff);
 
		// set attribute to staff element
		Attr attr = doc.createAttribute("id");
		attr.setValue("1");
		staff.setAttributeNode(attr);
 
 
		// firstname elements
		Element firstname = doc.createElement("Vorname");
		firstname.appendChild(doc.createTextNode("Tim"));
		staff.appendChild(firstname);

 
		// write the content into xml file
		TransformerFactory transformerFactory = TransformerFactory.newInstance();
		Transformer transformer = transformerFactory.newTransformer();
		
	    //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
	    transformer.setOutputProperty(OutputKeys.VERSION, "1.0");
	    transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-15");
	    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
		
		DOMSource source = new DOMSource(doc);
		StreamResult result = new StreamResult(new File("C:\\Users\\Desktop\\Test_" + (System.nanoTime()) + ".FMD"));
		
		// Output to console for testing
		// StreamResult result = new StreamResult(System.out);
 
		transformer.transform(source, result);
 
		System.out.println("File saved!");
 
	  } 
	  catch (ParserConfigurationException pce) 
	  {
		pce.printStackTrace();
	  }
	  catch (TransformerException tfe) 
	  {
		tfe.printStackTrace();
	  }
	}
}
```


----------



## Lodorvonhal (12. Feb 2014)

setz mal den boolean in Zeile 27 auf 'false'


----------

