JAXP and filter chains.

JAXP and filter chains.

Post by Benjamin Johnsto » Tue, 12 Feb 2002 16:13:50



Hello,

This is driving me crazy... I need to use XML filter chains with the JAXP
SAX parser as the parent of the entire chain because of the design of my
application.

But, this works inconsistently, sometimes it generates exceptions other
times it just creates a blank output file (with just the <?xml ...?>
header), other times it throws exceptions. Though, when I try different
approaches in experiments, or apply the same chain to my own specialized
XMLReader it all works perfectly.

Here's the smallest example that reproduces the problem:
    SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    SAXTransformerFactory stf =
        (SAXTransformerFactory)TransformerFactory.newInstance();
    XMLFilter xsltFilter = stf.newXMLFilter(new StreamSource(new
        File("transform.xsl")));
    xsltFilter.setParent(sp.getXMLReader());

    InputSource is = new InputSource(new StringReader(
        "<hello a=\"b\"><there c=\"d\"/></hello>"
    ));
    SAXSource cif = new SAXSource(xsltFilter, is);

    // and send it, via an empty transform, to the output stream
    Transformer transformer = stf.newTransformer();
    FileOutputStream fos = new FileOutputStream(output);
    transformer.transform(cif, new StreamResult(fos));
    fos.close();

And for this, I use a simple transform:
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>

    <xsl:template match="/">
        <xsl:copy-of select="."/>
    </xsl:template>

</xsl:stylesheet>

The generated exception appears below my signature.

Yet, a similar sample of code that doesn't use the identity transform at
the end (ie. the transformer is supplied the stylesheet) works perfectly.

After 5 hours experimenting with this (and even attempting to debug the
JAXP sources) I give up... can you see any errors in my code???, or
is there a bug in the libraries.

(oh, I sooo hope it isn't something really simple :)

I'm using the latest Sun JAX Pack.

Thanks for your help,

-Benjamin Johnston

javax.xml.transform.TransformerException: java.lang.RuntimeException:
java.lang.NullPointerException

        at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:469)

        at
com.blah blah blah...

---------

java.lang.RuntimeException: java.lang.NullPointerException

        at
org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:524)

        at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)

        at
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)

        at
org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:134)

        at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:452)

        at
com.blah blah blah...

---------

java.lang.RuntimeException: java.lang.NullPointerException

        at
org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:3170)

        at
org.apache.xalan.transformer.TransformerHandlerImpl.endDocument(TransformerHandlerImpl.java:433)

        at
org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:508)

        at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)

        at
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)

        at
org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:134)

        at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:452)

        at
com.blah blah blah...

Exception in thread "main"

 
 
 

1. problems chaining sun multi schema validator filter to transform filter

Hello

I have been playing with the Sun MultiSchema Validator a bit, and I
must say, I like it. I had been thinking about cobbling together
something similar for a project I am working on, but this thing is
better.

Anyway - I am having what I am sure is a simple problem, but I have
not been able to figure it out.

Basically, I have an xml document that I am transforming to a new
document that validates against an XML Schema. This document and its
corresponding xsl is part of a production system that works fine (and
uses Xerces and Xalan). I can transform using something like

              TransformerFactory tFactory = TransformerFactory.newInstance();
                    SAXTransformerFactory saxTFactory = ((SAXTransformerFactory)
tFactory);

            javax.xml.transform.TransformerFactory tfactory =
javax.xml.transform.TransformerFactory.newInstance ();
            xmlFilter = saxTFactory.newXMLFilter(source);

        i create a verifier filter as in

        VerifierFactory factory = new
com.sun.msv.verifier.jarv.TheFactoryImpl ();
        final org.iso_relax.verifier.Verifier verifier = factory.newVerifier
(schemaFile);
        filter = verifier.getVerifierFilter ();

just basic stuff here.

If i do my transform, and serialize it, the transform works perfectly.

If i load the transformed document using an xmlreader, and validate
that using the verifier filter, that works perfectly too. I can
introduce errors and they are reported perfectly. If i chain the
verifier to the transformer, however, I get this error:

com.sun.msv.verifier.ValidityViolation: unexpected attribute
"xmlns:xsi"

if the output from the transformer gets serialized and re-read, then
the error goes away. I even wrote a dumb little filter that serializes
to a string and back, and stuck that inline, and the problem goes
away.

Im thinking that there is some issue with encoding, or output format,
or somethng somewhere.

The stylesheet's encoding is set to UTF-8 and its output type is XML.
namespaces are all correctly defined.

any help would be appreciated.

Thanks.

Chris

2. Reading LF within RPG with OVRDBF

3. DOM Document to SAX Filter Chain

4. Out of Business

5. XSL filtering - can you filter on something like $contains$ ?

6. QD6580 controller and 3 drives

7. Supply Chain / Oracle database conversion with XML

8. Simple question.

9. SAXResult with XMLFilter chain

10. XSL SAX chaining and Validation (JAVA)

11. Is there any xml standard for 'transmission chain'

12. XML Standards in Supply-Chain Management

13. Chaining two stylesheets with te XSQL Servlet