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

Les Hill leh at galaxynine.com
Sun Apr 21 19:53:58 PDT 2002

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");

        if (this.docType != null) {

        this.docType = docType;

        // Similar to RE
        int REindex = content.indexOfFirstElement();
        int DTindex = content.indexOfDocType();
        if (DTindex < 0 && REindex < 0) {
            // Add to content
        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

More information about the jdom-interest mailing list