Reputation: 111
I like to write an xml Elem to a file, but I want to set the line separator between each node of the elem, so when opening the file under windows or ubuntu I have the correct format. for example :
val lineSep = System.getProperty("line.separator")
val xmlData : Elem = <person>
<firstName>John</firstName>
<lastName>Doe</lastName>
<emails>
<email type=”primary”>[email protected]</email>
<email type=”secondary”>[email protected]</email>
</emails>
<address>
<street>595 Market Street</street>
<city>San Francisco</city>
<zip>94105</zip>
</address>
</person>
val xmlStreamWriter = XMLOutputFactory.newInstance.createXMLStreamWriter(outputstream)
xmlStreamWriter.writeDTD(xmlData)
How to write it into a file considering the lineSeparator? the XMLOutputFactory have the method setProperty() is it possible to specify the line separator here?
Upvotes: 0
Views: 77
Reputation: 159135
From The standard Scala XML library - Getting started guide:
To write XML to a file:
scala.xml.XML.save("books.xml", books)
To format XML use the
scala.xml.PrettyPrinter
to configure the line length and indentation level:val pp = new scala.xml.PrettyPrinter(24, 4) pp.format(books)
Upvotes: 0