[jdom-interest] XMLOutputter andnewlinesafterdeclaration/doctype

Elliotte Rusty Harold elharo at metalab.unc.edu
Fri Dec 20 12:56:09 PST 2002

At 10:03 AM -0700 12/20/02, Alex Rosen wrote:
>Yup, I was talking about text editors.
>That is a good point about not handling newlines in Vadim's case (which
>is separate from the case that I'm talking about). Although, what if he
>used a FilterOutputStream to post-process the output of XMLOutputter,
>and replaces all newline characters with &x10; or &x13; as appropriate?
>Are character references allowed outside of the root element (e.g. right
>after the XML declaration)?

No, they're not.

There's no rule in XML that says there can only be one document in a 
file, but for practical reasons if you're going to put several 
documents in the same file, you're going to need a really solid way 
to tell where one document ends and the next begins. You can't rely 
on finding the end of the root element because there might be content 
after that which could either belong to that document or the next one.

The sensible way to do this (which I think somebody else already 
suggested) is to use a character that is *illegal* in XML such as a 
null or a vertical tab as the document delimiter within the file. 
This makes it very easy to find the document boundaries within the 
file, with no chance of confusing legal content with a document 
delimiter. This is far more robust and much easier to implement than 
any solution that relies on legal XML characters.

| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|          XML in a  Nutshell, 2nd Edition (O'Reilly, 2002)          |
|              http://www.cafeconleche.org/books/xian2/              |
|  http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/  |
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |

More information about the jdom-interest mailing list