Dave Flanagan wrote:
Murray,
Not sure if this will help get you started but here is a simple
transform using JAXP to both parse and serialize the resultant
Document object.
Running it agains the file shown below might give you some insight
<html>
<style>a < b</style>
</html>
I think you will find that JAXP is NOT placing the contents of <style>
inside a CDATA tag - although this can be done as an option using
another of the OutputKeys proeprties.
hope this helps
Dave Flanagan
Dave,
Yes, thanks very much. I've managed to build a few different methods
around that core functionality, such as setting up the output properties
based on the variety of known factors about the document. Here's another
hash at the basics:
public static boolean serialize( Node node, Object out, String method )
{
try {
DOMSource source = new DOMSource(node);
TransformerFactory tff = TransformerFactory.newInstance();
Transformer tf = tff.newTransformer();
tf.setOutputProperty(OutputKeys.METHOD,method);
if ( out instanceof Writer ) {
tf.transform(source,new StreamResult((Writer)out));
} else if ( out instanceof OutputStream ) {
tf.transform(source,new StreamResult((OutputStream)out));
} else {
tf.transform(source,new StreamResult((File)out));
}
return true;
} catch ( TransformerConfigurationException tce ) {
System.err.println("error configuring serializer for "+method+" method:
"+tce.getMessage());
} catch ( TransformerException te ) {
System.err.println("serializer error: "+te.getMessage());
}
return false;
}
Dave and Michael, thanks very much for your help. Over all the
thrashing about, I've at least cleaned up all serialization tasks
within my application, so that now everything calls one or two
methods that are now using the JAXP Transformation API, which is
(as one can see above) quite simple.
The only place this didn't work for me was when I needed to keep
a DOM serializer around to receive Nodes during a long task, rather
than serializing an already-completed Document.
I also like the whitespace handling a bit better with this one.
Only thing I'm missing (that I can think of right now) is being
able to set the end of line character.
Thanks!
Murray
......................................................................
Murray Altheim http://kmi.open.ac.uk/people/murray/
Knowledge Media Institute
The Open University, Milton Keynes, Bucks, MK7 6AA, UK .
The Pentagon announced that the US death toll had reached 1,001 -
three of them civilian contractors - since US-led forces moved in
to Iraq to topple Saddam Hussein 18 months ago. The number of
wounded had reached 7,000. The White House paid tribute to those
who had lost their lives. "We remember, honour and mourn the loss
of all those that made the ultimate sacrifice defending freedom,"
said US presidential spokesman Scott McClellan.
He added that the best way to honour them was to continue waging the
war on terror making "the world a safer place and make America more
secure". -- http://news.bbc.co.uk/1/hi/world/middle_east/3636340.stm
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]