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 "Roytman, Alex" <ro...@peacetech.com> on 2001/04/11 21:29:17 UTC

[PROPOSAL] Setting Xerces Specific Features via JAXP

Dear Xerces developers and users,

Right now Xerces specific features like
"http://apache.org/xml/features/dom/defer-node-expansion" can not be set via
JAXP. 

I propose to make a small modification to implementation of Xerces JAXP to
support Xerces specific features.
I am not JAXP specs guru but according to Sun
DocumentBuilderFactory.setAttribute() 
"Allows the user to set specific attributes on the underlying
implementation".

The changes to existing JAXP implementation are minimal - modify
DocumentBuilderFactoryImpl to implement setAttribute() and getAttribute()
methods (they throw not implemented exception now) and modify
DocumentBuilderImpl to read these attribute and set DOMParser features
accordingly.

The usage pattern would be:
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilderFactory.setAttribute("http://apache.org/xml/features/dom/defe
r-node-expansion", Boolean.FALSE);

Below is a modified DocumentBuilderImpl source.
I also attached both DocumentBuilderFactoryImpl.java and
DocumentBuilderImpl.java
Right now it is a quick fix I am using to resolve the problem but if you
think it useful 
I will be glad to look into it more, clean it up and provide the fix.
 

public class DocumentBuilderImpl extends DocumentBuilder {
    /** Xerces features */
    static final String XERCES_FEATURE_PREFIX =
                                        "http://apache.org/xml/features/";
    static final String CREATE_ENTITY_REF_NODES_FEATURE =
                                        "dom/create-entity-ref-nodes";
    static final String INCLUDE_IGNORABLE_WHITESPACE =
                                        "dom/include-ignorable-whitespace";

    private DocumentBuilderFactory dbf;

    private EntityResolver er = null;
    private ErrorHandler eh = null;
    private DOMParser domParser = null;

    private boolean namespaceAware = false;
    private boolean validating = false;

    DocumentBuilderImpl(DocumentBuilderFactory dbf)
        throws ParserConfigurationException
    {
        this.dbf = dbf;

        domParser = new DOMParser();

        try {
            // Validation
            validating = dbf.isValidating();
            String validation = "http://xml.org/sax/features/validation";
            domParser.setFeature(validation, validating);

            // If validating, provide a default ErrorHandler that prints
            // validation errors with a warning telling the user to set an
            // ErrorHandler
            if (validating) {
                setErrorHandler(new DefaultValidationErrorHandler());
            }

            // "namespaceAware" ==  SAX Namespaces feature
            namespaceAware = dbf.isNamespaceAware();
            domParser.setFeature("http://xml.org/sax/features/namespaces",
                                 namespaceAware);

            // Set various parameters obtained from DocumentBuilderFactory
            domParser.setFeature(XERCES_FEATURE_PREFIX +
                                 INCLUDE_IGNORABLE_WHITESPACE,
                                 !dbf.isIgnoringElementContentWhitespace());
            domParser.setFeature(XERCES_FEATURE_PREFIX +
                                 CREATE_ENTITY_REF_NODES_FEATURE,
                                 !dbf.isExpandEntityReferences());

            // XXX No way to control dbf.isIgnoringComments() or
            // dbf.isCoalescing()

//------- FIX -------------------------------------------------
            final String DEFER_NODE_EXPANSION = 
             "http://apache.org/xml/features/dom/defer-node-expansion";
            Boolean b = (Boolean)dbf.getAttribute(DEFER_NODE_EXPANSION);
            if (b != null) {
              domParser.setFeature(DEFER_NODE_EXPANSION, b.booleanValue());
            }
// Any other xerces specific features ...
//------- END OF FIX ------------------------------------------

        } catch (SAXException e) {
            // Handles both SAXNotSupportedException,
SAXNotRecognizedException
            throw new ParserConfigurationException(e.getMessage());
        }
    }            }




-----Original Message-----
From: Edwin Goei [mailto:Edwin.Goei@sun.com]
Sent: Wednesday, April 11, 2001 1:33 PM
To: general@xml.apache.org
Subject: Re: ApacheCon 2001, JAXP 1.1 talk slides


> "Roytman, Alex" wrote:
> 
> Hello Edwin,
> 
> I am afraid I might sound a little bit anxious so please pardon me :-)
> 
> Some time ago I created a defect "Setting SAXParser/DOMBuilder
> features via JAXP"
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1143
> 
> Right now there is no way to set certain Parser/DOMBuilder features
> via JAXP
> for example "http://apache.org/xml/features/dom/defer-node-expansion"
> which causes us a lot of grief
> 
> So far I have not got any reply whether this feature is going to be
> implemented or not.
> There is nothing about it in Xerces 1.4 release plan and nobody has
> touched the defect so far.
> 
> There was some talk mailto:nboyd@atg.com on the mailing list that it
> is delayed because Sun has not clarified proper usage of
> DocumentBuilderFactory.setAttribute()/getAttribute() is it true?

These two methods are probably where the
"http://apache.org/xml/features/dom/defer-node-expansion" feature would
be exposed via JAXP if I read the spec right.  I am not the spec lead
for JAXP so you may want to send your comments to
jsr63-comments@eng.sun.com.  This feature would then be parser
specific.  If you want a parser independent feature name, then that
would probably go into the next version of JAXP as version 1.1 has
already been finalized.  At some point a new JSR (Java Specification
Request) will probably be proposed for the next version of JAXP.

-Edwin

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org