java: make (xslt) transformer throw exception on error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • killy971

    java: make (xslt) transformer throw exception on error

    I am using the following syntax, with Xalan, to process xml
    transformations in java:

    StreamSource xml = new StreamSource(xm lFile);
    StreamSource xsl = new StreamSource(xs lFile);
    StreamResult out = new StreamResult(ou tputFile);

    TransformerFact ory factory = TransformerFact ory.newInstance ();
    Transformer transformer = factory.newTran sformer(xsl);
    transformer.tra nsform(xml, out);

    If the xslt sheet input is broken (invalid xml, etc.), an exception is
    thrown (fatal error occurs), but if the input xml file (file to
    transform) is broken no exception is thrown (because it is not a fatal
    error).
    I would like to knwo if there is a way to make the transformer throw
    an exception on this kind of errors, or if there is a way to check if
    an error has occured after the "transform( )" call.
  • Johannes Koch

    #2
    Re: java: make (xslt) transformer throw exception on error

    killy971 schrieb:
    I am using the following syntax, with Xalan, to process xml
    transformations in java:
    >
    StreamSource xml = new StreamSource(xm lFile);
    StreamSource xsl = new StreamSource(xs lFile);
    StreamResult out = new StreamResult(ou tputFile);
    >
    TransformerFact ory factory = TransformerFact ory.newInstance ();
    Transformer transformer = factory.newTran sformer(xsl);
    transformer.tra nsform(xml, out);
    >
    If the xslt sheet input is broken (invalid xml, etc.), an exception is
    thrown (fatal error occurs), but if the input xml file (file to
    transform) is broken no exception is thrown (because it is not a fatal
    error).
    Parse the xmlFile with a DocumentBuilder , then pass a DOMSource with the
    resulting Document to the transform method. In case the xmlFile is not
    wellformed you'll get an Exception from the DocumentBuilder .

    --
    Johannes Koch
    In te domine speravi; non confundar in aeternum.
    (Te Deum, 4th cent.)

    Comment

    Working...