473,493 Members | 4,319 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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(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).
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.
Aug 6 '08 #1
1 2367
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.)
Aug 6 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4191
by: Michael | last post by:
Hello I am trying to write a Java-Program which converts a XML-file in a HTML. It should take the Transformation-file from the XML-file itself. Below find a possible XML-file: <?xml...
0
2887
by: Dominique Bejean | last post by:
Hello, I am having a problem doing an XSLT transformation using Java. I have a XML document as a DOM Document object, wrap the Document object with a DOMSource object, and do the...
0
2995
by: Xiaolei Li | last post by:
first off, i'm a total newbie at this stuff so excuse any wrong usage of terminology or whatever else. i have a XSL to transform a Document such that all "text" nodes will have a "SPAN" inserted...
1
3084
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
2
3321
by: Robert M. Gary | last post by:
I'm using JRE 1.5 on Solaris Japanese (Sparc). The JVM claims its default character set is EUC-JP I'm seeing two strange things when using Japanese character sets... 1) If I write a program that...
5
1389
by: crazydiode | last post by:
HI All, I am new to XSLT. I am trying to use xslt with xml in my java code. I am basically trying to replace one node of the original xml with my own node. I defined the xslt as follows: ...
6
4960
by: Lenny Wintfeld | last post by:
Hi I'm attempting additions/changes to a Java program that (among other things) uses XSLT to transform a large (96 Mb) XML file. It runs fine on small XML files but generates OutOfMemory...
0
1355
by: Hugh Field-Richards | last post by:
Hi This was original posted only on the Cocoon Users Group last year but Paloose is now reasonably mature enough for exposure on this forum. Paloose is a simplified (much simplified) version...
4
25750
by: BibhuAshish | last post by:
Hi, I wanted to delete a line from xml file which i did it. But after deletion of that line there is a blank space. Again if i am adding another line by using java that blank line remains as...
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.