Subjects
Home
Xalan extension functions
Fomatting question serializing DOM with pretty print
xalan with pull parser
Cannot find the declaration
Apache Xalan drop support to run on JRE 1 1 x
Why does Doctype change processing of a document
Node set to XML string via Java extensions in Xalan J: possible?
Templates/Transformers + thread safety???
Problem evaluating xpath with muliple prefix with different namespace
remove an arbitrary attribute from xsl output
Xalan3 XSLT 2 0 XPath 2 0 support?
Problem using compiled translets with Xalan !!
Xalan and jstl 1 1 problem with transform tag
NullPointer in DOM2DTM getLocalName
URIResolvers base parameter with xsltc and cascaded imports
Performance problem for Xalan J on intel dual core
Standard libraries in JAXP?
Serializing a DOM tree to XML file, customize entities replacement
Library Conflict Involving BCEL Library
A question on how users are using <xsl:message >
Kevin Cormier as a new Apache Xalan J committer
Struggling to iterate over tokenized string
Xalan count() trouble
Problem with recursive xpath
Error when switching to java 1 5
document( ' ')
Problem with Xalan2 7 0 transformation
cr/lf options
entity encoded XML
can xalan transform 2 xml using one xslt?
Xalan J JIRA defect review Monday October 16, 2006 from 2:00 to 3:30 pm ED
xsl transform with cdata section elements
xslt parameters not expanded
Weird behavior of XPath evaluate()
How to avoid <xsl:message > instruction prints stylesheet file informations ?
Cannot find SimpleTransform subdirectory after installing Xalan J
recover from document not found exceptions
jdk1 5 and Xalan jar differences?
Performance Issue
Error/Bug adding floating point numbers
XPathAPI: eval exp using nodes with default namespace
modifying xalan to output invalid XML
NullPointerException
mege two separate xml nodes into one
Is this a XALAN document identification bug?
is StylesheetRoot really java io Serializable ?
transform() fails for DOMSource but succeeds for StreamSource
Thoughts on Transformer parameter passing
HELP, Xalan and jstl 1 1 problem with transformer
Problem with XPath namespace axis?
string utils:replace deleting search string if replacement string is an HTML
help with enumeration values pls
xalan 2 5 1 vs 2 7 performance question
How to insert/update in XML document
HTML Serialization and Handling of Ampersands in HREF Attributes
XHTML link tag stripping
SystemId Unknown; Line #24; Column #49; java lang NullPointerException
xpath text() help
Apostrophe problem with xalan 2 7 0
How to set variables in XML document?
Links
Home
Oracle database error code ...
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
EntityResolver in a document() function to solve OASIS Catalog

EntityResolver in a document() function to solve OASIS Catalog

2006-10-15       - By Marc
Reply:     1     2  

Hello,

I try to use the OASIS Catalog to solve the PUBLIC DTD.
All is OK but I have a problem with the XML file charged by the document().
I use the CatalogResolver with the setURIResolver for the Factory, and the
setEntityResolver for the XMLReader, but I don't find how the set the
Entityresolver for the XMLReader used by the transformer.
Here is my code :
           SAXTransformerFactory tFactory = (SAXTransformerFactory)
TransformerFactory.newInstance();
           
           // on met en place la gestion du catalog
           CatalogResolver ct = new CatalogResolver();
           tFactory.setURIResolver(ct);
           javax.xml.transform.sax.TemplatesHandler templatesHandler =
                   tFactory.newTemplatesHandler();
           
           // Create an XMLReader and set its ContentHandler.
           org.xml.sax.XMLReader reader =
                   org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
           reader.setContentHandler(templatesHandler);
           reader.setEntityResolver(new CatalogResolver());
           // Parse the stylesheet.
           reader.parse(fichierXSLT);
           // Get the Templates object (generated during the parsing of the
stylesheet)
           // from the TemplatesHandler.
           javax.xml.transform.Templates templates =
                   templatesHandler.getTemplates();
           // Create a Transformer ContentHandler to handle parsing of
           // the XML Source.
           javax.xml.transform.sax.TransformerHandler transformerHandler
                   = tFactory.newTransformerHandler(templates);
           // Reset the XMLReader's ContentHandler to the TransformerHandler.
           reader.setContentHandler(transformerHandler);
           // Set the ContentHandler to also function as a LexicalHandler,
which
           // can process "lexical" events (such as comments and CDATA).
           reader.setProperty("http://xml.org/sax/properties/lexical-handler",
                   transformerHandler);
           
           // Set up a Serializer to serialize the Result to a file.
           org.apache.xml.serializer.Serializer serializer =
                   org.apache.xml.serializer.SerializerFactory.getSerializer
                   (org.apache.xml.serializer.OutputPropertiesFactory
.getDefaultMethodProperties
                   ("xml"));
           serializer.setOutputStream(new java.io.FileOutputStream
(fichierSortie));
           // The Serializer functions as a SAX ContentHandler.
           javax.xml.transform.Result result =
                   new javax.xml.transform.sax.SAXResult(serializer
.asContentHandler());
           transformerHandler.setResult(result);
           
           // Parse the XML input document.
           reader.parse(fichierEntree);
I try something more simple with a transformer without contentHandler but it's
the same:
           SAXTransformerFactory tFactory = (SAXTransformerFactory)
TransformerFactory.newInstance();
           
           // on met en place la gestion du catalog
           CatalogResolver ct = new CatalogResolver();
           tFactory.setURIResolver(ct);
           
           // Use the TransformerFactory to instantiate a Transformer that
will work with
           // the stylesheet you specify. This method call also processes the
stylesheet
           // into a compiled Templates object.
           InputSource inputXSLT = new InputSource(new FileReader(new File
(VerifFichierServeurXSL(fichierXSLT))));
           Source sourceXSLT = new StreamSource(inputXSLT.getCharacterStream()
, inputXSLT.getSystemId());
           Transformer transformer = tFactory.newTransformer(sourceXSLT);
           //   Transformer transformer = tFactory.newTransformer(new
StreamSource(fichierXSLT));
           XMLReader XMLr;
           //get a SAXParserFactory instance
           SAXParserFactory SAXpf=SAXParserFactory.newInstance();
           
           //enabling the namespaces processing
           if(SAXpf.isNamespaceAware()==false)
               SAXpf.setNamespaceAware(true);
           
           //get a SAXParser object
           SAXParser SAXparser=SAXpf.newSAXParser();
           
           //get the XMLReader
           XMLr=SAXparser.getXMLReader();
           XMLr.setEntityResolver(new CatalogResolver());
           
           //creating the SAXSource
           SAXSource sXML=new SAXSource(XMLr, new InputSource
                   (fichierEntree));
           sXML.setXMLReader(XMLr);
           transformer.transform(sXML, fichierSortie);

If someone as an idea?

Thank's

Marc