[email protected]
[Top] [All Lists]

Re: Problem reading in content created by LSSerializer

Subject: Re: Problem reading in content created by LSSerializer
From: Michael Glavassevich
Date: Fri, 8 Sep 2006 12:39:12 -0400
Chad la Joie <[email protected]> wrote on 09/07/2006 07:11:26 AM:

> Thank you Michael, by using the LSOutput with my FileWriter I was able 
> to get this to work.  For those who may have also encountered this 
> problem, the actual code is below.

You may find this doesn't work if you try running your app on another 
platform. I still recommend feeding the serializer an OutputStream ( i.e. 
serializerOut.setByteStream(new FileOutputStream(outputFile)); ). There 
are good reasons for using a Writer but it's often the wrong choice.

> Looking at this further, how would the use of an LSParser w/ LSInputs 
> compare to using the DocumentBuilder JAXP interface?

See DocumentBuilder.parse(InputSource). An LSInput contains all of the 
fields of an InputSource and has a few more of its own.

> Is the LSParser 
> just DOM 3's answer to the lack of a parser interface in the DOM 1 & 2 
> standards


> , or is it something more?

Well... It also has capabilities which a DocumentBuilder doesn't have such 
as filtering and asynchronous parsing.

> Again, thanks for the help.
> ---------------------
> public void writeXML(Element element, File outputFile) throws Exception{
>     DOMImplementation domImpl = 
> element.getOwnerDocument().getImplementation();
>     DOMImplementationLS domImplLS = (DOMImplementationLS) 
> domImpl.getFeature("LS", "3.0");
>     LSSerializer serializer = domImplLS.createLSSerializer();
>     LSOutput serializerOut = domImplLS.createLSOutput();
>     serializerOut.setCharacterStream(new FileWriter(outputFile));
>     serializer.write(element, serializerOut);
> }
> -- 
> Chad La Joie             2052-C Harris Bldg
> OIS-Middleware           202.687.0124
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [email protected]
E-mail: [email protected]

[email protected]----
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

<Prev in Thread] Current Thread [Next in Thread>