W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2008

How does DOM model whitespace before the document element?

From: Guven Demir <guven.internet@gmail.com>
Date: Wed, 19 Mar 2008 14:39:28 +0200
Message-ID: <eb2d0f0803190539ge138e11xc41213f5a9d7caa2@mail.gmail.com>
To: www-dom@w3c.org
Hi all,

I failed to understand how DOM models whitespace before the document

E.g. in the following fragment, the white space between the XML declaration
and the starting tag of the <root> element:

<?xml version="1.0" encoding="UTF-8"?>

    <child />

When I parse such a document and get the DOM objects using DocumentBuilder
(in java), then later write the objects back to a file using Transformer,
the whitespace is preserved. But I cant see the object responsible for the
whitespace in the DOM object tree.

And also, when I try to insert a text element before the document element I
get an exception indicating "HIERARCHY_REQUEST_ERR: An attempt was made to
insert a node where it is not permitted." This is consistent with DOM level1
spec, as text nodes dont seem to

This means that I cant insert whitespace before the document element when
I'm programmatically creating the document, and my document becomes:

<?xml version="1.0" encoding="UTF-8"?><root>
    <child />

Though identical in semantics, it does not look very good and readable.

Any ideas or knowledge on this?

Thanks in advance,
Received on Thursday, 20 March 2008 04:23:39 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:13 UTC