[jdom-interest] Problem using Tip: Using JDOM and XSLT by Brett
McLaughlin
Ian Lea
ian.lea at blackwell.co.uk
Fri Oct 12 02:34:12 PDT 2001
I tend to avoid PipedInput/Output streams wherever possible
since they have considerable scope for lockups. Perhaps you
could use StringReaders/Writers or the ByteArray equivalents
instead.
Or look into JDOMSource and JDOMResult, or, unless you are
tied to Xalan, look at Saxon which has a DocumentWrapper
class which wraps a JDOM Document and feeds it straight into
a transformer. I use code like this:
import ...
import com.icl.saxon.jdom.DocumentWrapper;
Document jdoc = buildJdoc(xml);
DocumentWrapper docw = new DocumentWrapper(jdoc, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamResult baossr = new StreamResult(baos);
getSaxonTransformer(xsl).transform(docw, baossr);
and then do what I want with the output.
--
Ian.
ian.lea at blackwell.co.uk
Jason Long wrote:
>
> I am attempting to make use of "Listing 1. Using JDOM with Xalan-J 2" which
> can be found at the following url:
> http://www-106.ibm.com/developerworks/java/library/x-tipjdom.html
>
> Here is my system configuration:
> W2K Advanced Server
> JDK 1.4 beta 2
> Tomcat 4.0 Final
> JDOM beta 7
>
> I have been working on a servlet that compiles a list of some files on my
> server, parses their names, and generates an xml file. For this JDOM worked
> beautifully. I had used SAX and DOM before and had many headaches. Due to
> JDOM's ease of use I had my application building the XML file in no time.
> Now it was time to transform the XML using XSL so that it could be displayed
> to match the rest of my site. I simply pasted the transform method from
> "Listing 1. Using JDOM with Xalan-J 2" in the previously mentioned tip and
> added the appropriate jar files for Tomcat. Everything compiled properly,
> but my browser just hangs and never gets a reply. I began by commenting out
> all of the code and adding one line at a time until it began to fail. Here
> is where my code hangs:
>
> // Output to the I/O stream
> xmlOutputter.output(sourceDoc, sourceOut);
>
> Unless I comment out this line and the rest of the code that follows which
> depends on this line the servlet never responds back. It seems that I have
> Xalan installed properly because the code previous to this point depends on
> it and the point where the servlet freezes has nothing to do with it. I
> have yet to resolve this problem, but am very excited about JDOM. I would
> appreciate and assistance with this matter.
>
> Best Regards,
>
> Jason Long
> JML Internet Enterprise - www.jmlie.com
> BS Physics, MS Chemical Engineering
More information about the jdom-interest
mailing list