[jdom-interest] Beta8 Document and DocType semantics incorrect?

Jason Hunter jhunter at servlets.com
Mon Apr 22 09:44:19 PDT 2002


In JDOM the DocType is not treated as content of the document; it's
treated as a property of the document.  That's far more natural for
programmers.  I don't believe this violates production 22 because that's
for the *text* representation of the document, and JDOM both outputs and
reads XML in accordance with that production rule.

-jh-

Les Hill wrote:
> 
> The beta8 implementation of Document.setDocType() looks incorrect.
> Specifically, it seems to fail production 22 of the XML spec+.  As a
> side-effect of this, Document.getContent() should return all children of the
> Document including the DocType, in order.
> 
> An implementation should fall along similar lines to
> Document.setRootElement() -- this will not compile because ContentList does
> not accept DocType:
> 
>     public Document setDocType(DocType docType) {
>         if (docType != null) {
>             if (docType.getDocument() != null) {
>                 throw new IllegalAddException(this, docType,
>                           "The docType already is attached to a document");
>             }
>             docType.setDocument(this);
>         }
> 
>         if (this.docType != null) {
>             this.docType.setDocument(null);
>         }
> 
>         this.docType = docType;
> 
>         // Similar to RE
>         int REindex = content.indexOfFirstElement();
>         int DTindex = content.indexOfDocType();
>         if (DTindex < 0 && REindex < 0) {
>             // Add to content
>             content.add(docType);
>         }
>         else if (DTindex >= 0) {
>             // Replace previous
>             content.set(DTindex, docType);
>         }
>         else {
>             // We have comments, pis, and a RE -- add just before RE
>             content.insert(REindex, docType);
>         }
> 
>         return this;
>     }
> 
> + Remind me of the irony of this message some other time, I am sure it will
> crop up :)
> 
> Les Hill
> leh at galaxynine.com
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list