1
Element element = new Element("root");
Document document = new Document(element);

document will auto generate <?xml version="1.0"?>

<?xml version="1.0"?>
<root>
</root>

How to set encoding, standalone into xml declaration use XOM ? I expect:

<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<root>
</root>
Luke Le
  • 728
  • 1
  • 9
  • 24
  • Duplicate of http://stackoverflow.com/questions/10582968/how-to-set-utf-16-encoding-format-for-xml – klog Mar 24 '16 at 08:57
  • If not a duplicate then see http://www.xom.nu/tutorial.xhtml, `Serializer serializer = new Serializer(System.out, "ISO-8859-1");` – klog Mar 24 '16 at 09:02
  • @klog Thanks for reply, but Serializer(OutputStream out, String encoding) , how to set "standalone"? – Luke Le Mar 24 '16 at 09:09

1 Answers1

1

Short answer: you can't do that.

XOM deliberately does not expose or emit the standalone declaration. In 18 years of XML, I can't recall a single case where the standalone declaration has been necessary or useful; and XOM makes a point of shielding developers from features they shouldn't concern themselves with.

The standalone declaration likely doesn't do what you think it does in any case. For instance, both of the highest voted answers on this question are wrong. I'll add a correct answer to that question when I get a minute.