Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to connect OutputStream and DOM document ?

Status
Not open for further replies.

khho9

MIS
Mar 13, 2003
6
0
0
HK
Hi all ,

I am trying to use stxx with jaxb. there are two method I don't quite know how to connect them :

in jaxb, I have to

saveDocument(HttpRequest, Document)

while in stxx, I have to
foo.marshal( Object, System.out );
(I think should be foo.marshal( Object, OutputStream) )

Now I want to saveDocument marshalled by foo. ) How can I change the OutputStream to Document ?

Thanks.

Perseus
 
I don't know much about DOM objects, but you can redirect System.out to another output stream or a file. Here's how to direct it to a file:

PrintStream errPs = new PrintStream( new FileOutputStream( "myfile.txt" ), true );
System.setOut( errPs );

You can also redirect System.err the same way, with System.setErr().
"When you have eliminated the impossible, whatever remains, however
improbable, must be the truth." ~ Arthur Conan Doyle
 
The marshall method is overridden (from the JAXB Javadocs):

Marshalling to a DOM Node:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();

m.marshal( obj, doc );

Known stxx as I'm one of its developers, the best way would be to throw the marshaller in the request attributes, then extend the default serialization to recognize the marshaller and generate SAX events directly (you can pass the Mashaller a ContentHandler as well).

Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top