You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by se...@cern.ch on 2001/03/05 13:24:32 UTC

docType in case of non-default document-class-name

I'm having some problems with the
http://apache.org/xml/properties/dom/document-class-name property of the DOM parser.

Actually, when I set it to my own document implementation, which is an empty wrapper
around the default one, the documents do not have a document type. The parsing seems
however to be done correctly. Is it a bug in the default DocumentImpl implementation
?

Sebastien

Here is the code I use :

import org.apache.xerces.dom.*;
import org.apache.xerces.parsers.*;

public class Test2 {

  public static void main (String[] args) {
    DOMParser parser = new DOMParser();
    try {
      parser.setProperty("http://apache.org/xml/properties/dom/document-class-name",

                "MyDocumentImpl");
    } catch (org.xml.sax.SAXNotSupportedException e) {
    } catch (org.xml.sax.SAXNotRecognizedException e) {
    }
    try {
      parser.parse("File:///home/sponce/mycmt/Det/XmlEditor/v3d1/src/Test2.xml");
    } catch (java.io.IOException e) {
    } catch (org.xml.sax.SAXException e) {
    }
    Document document = parser.getDocument();
    DocumentType documentType = document.getDoctype();
    System.out.println(documentType);
  }

}

The MyDocumentImpl class :

import org.apache.xerces.dom.*;
import org.w3c.dom.*;

public class MyDocumentImpl extends DocumentImpl {

    public MyDocumentImpl() {
    super();
    }

    public MyDocumentImpl(boolean grammarAccess) {
        super(grammarAccess);
    }

    public MyDocumentImpl(DocumentType doctype) {
    super(doctype);
    }

    public MyDocumentImpl(DocumentType doctype, boolean grammarAccess) {
    super(doctype, grammarAccess);
    }

}

And the xml file I use for testing :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE DDDB SYSTEM "DTD/structure.dtd">
<DDDB>
</DDDB>


Re: docType in case of non-default document-class-name

Posted by se...@cern.ch.
I actually found the reason of this behavior : when you redefine
http://apache.org/xml/properties/dom/document-class-name, you lose everything
implemented in the DocumentImpl class (which is pretty normal) but also half of what is
implemented inside the DOMParser since it's directly and explicitely using the
DocumentImpl class.

What I would like is to keep this code, at least in case you're just subclassing
DocumentImpl to change its behavior. This could be done by applying the following
little patch to the parser :

Index: DOMParser.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/parsers/DOMParser.java,v
retrieving revision 1.40
diff -5 -r1.40 DOMParser.java
911a912
>                                               boolean isInstanceOfDocumentImpl =
Class.forName(DEFAULT_DOCUMENT_CLASS_NAME).isAssignableFrom(Class.forName(fDocumentClassName));

937a939,941
>
if (isInstanceOfDocumentImpl) {
>
fDocumentImpl = (DocumentImpl) fDocument;
>
}

Is it reasonnable ?
If yes, could someone commit it ?

Sebastien

sebastien.ponce@cern.ch wrote:

> I'm having some problems with the
> http://apache.org/xml/properties/dom/document-class-name property of the DOM parser.
>
> Actually, when I set it to my own document implementation, which is an empty wrapper
> around the default one, the documents do not have a document type. The parsing seems
> however to be done correctly. Is it a bug in the default DocumentImpl implementation
> ?
>
> Sebastien