xerces-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sandy...@ca.ibm.com
Subject Re: PSVI access through DOM in xerces-j
Date Thu, 21 Nov 2002 17:41:32 GMT
Try this:

            DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(true);
            factory.setAttribute
("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                                 "http://www.w3.org/2001/XMLSchema");
            factory.setAttribute
("http://apache.org/xml/properties/dom/document-class-name",
                                 "org.apache.xerces.dom.PSVIDocumentImpl");

            DocumentBuilder db= factory.newDocumentBuilder();
            Document document = db.parse(...);

Note that you need all the 4 things to get DOM PSVI: namespace, validation,
schema language, and document class.

The reason it's not a complete sample is that we are assuming people
reading this faq should already be familiar with schema validation (which
requires the first 3 settings). Also how to set those features/properties
differs from API to API, and we didn't want to provide all versions of
similar sample code for all possible API's. But I agree that it might help
if we had a sample program under samples/dom.

Hope this helps,
Sandy Gao
Software Developer, IBM Canada
(1-905) 413-3255
sandygao@ca.ibm.com



                                                                                         
                                             
                      ari@cogsci.ed.ac.                                                  
                                             
                      uk (K. Ari               To:       xerces-j-user@xml.apache.org    
                                             
                      Krupnikov)               cc:       ht@cogsci.ed.ac.uk              
                                             
                                               Subject:  PSVI access through DOM in xerces-j
                                          
                      11/18/2002 02:24                                                   
                                             
                      AM                                                                 
                                             
                      Please respond to                                                  
                                             
                      xerces-j-user                                                      
                                             
                                                                                         
                                             
                                                                                         
                                             



Hi guys,

I'm trying to use PSVI features in Xerces, and I need some help. I
understand Xerces 2.2.0 had a bug in the PSVI implementation that
caused NullPionterExceptions if you tried to run the samples. Sandy
was kind enough to point out that this bug had been fixed in 2.2.1,
and indeed xni.PSVIWriter now produces the expected output.

Now I'm trying to access the PSVI from
DOM. http://xml.apache.org/xerces2-j/faq-xs.html#faq-5 says:

   "Use http://apache.org/xml/properties/dom/document-class-name
   property to set org.apache.xerces.dom.PSVIDocumentImpl document
   interfaces implementation. In the resulting DOM tree, you may cast
   org.w3c.dom.Element to the org.apache.xerces.xni.psvi.ElementPSVI
   and org.w3c.dom.Attr to the
   org.apache.xerces.xni.psvi.AttributePSVI."

The code snippet that follows assumes that has been done. I assumed
that "use ... property to set ..." in the context of DOM means
inserting something like the following before the code in that sample:


    DocumentBuilderFactory factory =
        DocumentBuilderFactory.newInstance();
    factory.setAttribute
       ("http://apache.org/xml/properties/dom/document-class-name",
        "org.apache.xerces.dom.PSVIDocumentImpl");

This throws no exceptions (and I know it does *something*, because if
I pass in a nonexistent class name, I get a
``java.lang.IllegalArgumentException: PAR003 Class,
"org.apache.xerces.dom.PSVIDocumentImpl.bogus", not found.'')

Unfortunately, builders produced by this factory still return
org.apache.xerces.dom.ElementImpl objects, not PSVIDocumentImpl.

There must be something very simple I'm missing.

It would be nice if the sample included a complete working example,
one that compiles and produces the expected results. It wouldn't have
to be very long. As far as I can tell, it would only add about a
half-dozen lines to the 12-line long example on
http://xml.apache.org/xerces2-j/faq-xs.html#faq-5

Ari.

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





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


Mime
View raw message