Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - java: make (xslt) transformer throw exception on error [Thread Next] Re: java: make (xslt) transformer throw exception on errorTo: NULL Date: 8/6/2008 10:28:00 AM
killy971 schrieb:
> I am using the following syntax, with Xalan, to process xml
> transformations in java:
>
> StreamSource xml = new StreamSource(xmlFile);
> StreamSource xsl = new StreamSource(xslFile);
> StreamResult out = new StreamResult(outputFile);
>
> TransformerFactory factory = TransformerFactory.newInstance();
> Transformer transformer = factory.newTransformer(xsl);
> transformer.transform(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.)
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
