Summary

XML documents are text. This means that you can create an XML document using any technique you would normally use to create text files—including but not limited to output streams, writers, toString() methods, char arrays, or anything else that produces text. When you do this, you're responsible for maintaining well-formedness and validity. But, doing this is not hard, certainly no harder than debugging any other part of a program, and often considerably easier.

Because XML documents are text, it's best to use a Writer rather than an OutputStream to generate an XML document. However, because the Writer class has no standard method of determining what encoding it's using, you should normally build your Writer from an OutputStream you control, ...

Get Processing XML with Java™: A Guide to SAX, DOM, JDOM, JAXP, and TrAX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.