I use this code to enable newlines:
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
But I get following output:
<?xml version="1.0" encoding="UTF-8"?><root>
<child>aaaa</child>
</root>
I'd like to have newline before root element. What should I do?
XML Encodings xml version="1.0" encoding="ISO-8859-1"?> Without this information, the default encoding is UTF-8 or UTF-16, depending on the presence of a UNICODE byte-order mark (BOM) at the beginning of the XML file.
Yes. Android uses xml to declare layouts and java to provide logic. Note that while both activity_main and MainActivity follow common naming conventions, there is no need for them to be called this way.
Other answers did not work for me, or would be unacceptable in my application. This worked for me:
transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
Another solution is : transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "10");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With