You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Swanson, Brion" <Br...@westgroup.com> on 2001/06/19 16:12:03 UTC

DocumentImpl behavior against spec??

Hello all,
 
I've been playing around with Documents and programmatically adding comment
nodes
to a document.
 
I discovered that if comments exist in a document above the document element
when
parsed by the DOMParser, those elements persist in the document and will be
written
out again if left unchanged when the document is serialized.
 
I tested this theory first by printing out all the names of the child nodes
of the 
Document node (note: NOT the document element).  Sure enough, the comments
appeared before the document element.
 
Next I tried to insert a comment node before the document element on the
document
node and it worked without issue.
 
What confuses me is that it's my understanding that comment nodes,
processing
instructions, and all other types of nodes (except the two special ones:
<?xml?> and
<!DOCTYPE>) can only exist within a document.  (The DOMImplementation
interface
documentation says something to that effect as well.)  And I thought a
Document is 
defined (roughly) as the collection of XML (nodes) that occur between two
'document
elements' or 'root nodes' - an element which occurs only once within the
document 
and contains all other elements.
 
So how is it that comment elements can occur outside of the Document and
have no
particular API to deal with them, nor anywhere I found that states that
comments are
the exception to this specification (besides the other two)?
 
Just curious, thanks.
 
FYI - it's not causing a problem, and I rather like this 'feature' of
Xerces, but it does
seem to be one of those elusive specification quirks, and I'm curious if
that was just
an implementation decision on the part of the Xerces project.

-------------- 
Brion Swanson 
Software Engineer (Co-op) 
West Group - Public Records 
Brion.Swanson@westgroup.com 
716-327-6164 (x6164) 

 

Re: DocumentImpl behavior against spec??

Posted by Ian Roberts <ir...@decisionsoft.com>.
On Tue, 19 Jun 2001, Swanson, Brion wrote:

> I tested this theory first by printing out all the names of the child nodes
> of the 
> Document node (note: NOT the document element).  Sure enough, the comments
> appeared before the document element.

<snip />

> So how is it that comment elements can occur outside of the Document and
> have no
> particular API to deal with them, nor anywhere I found that states that
> comments are
> the exception to this specification (besides the other two)?

I think you've answered your own question here.  The Document node is NOT
the same as the document element.  The Document node is a kind of
"virtual" node, which doesn't have a representation in the XML.  It can
contain a number of children (such as PIs, comments, <!DOCTYPE> etc.), one
of which is the document element, inside which all the other elements in
the XML document occur.

Ian

-- 
Ian Roberts, Software Engineer        DecisionSoft Ltd.
Telephone: +44-1865-203192            http://www.decisionsoft.com


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org