j-users@xerces.apache.org
[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 <lajoie@xxxxxxxxxxxxxx> 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

Yes. 

> , 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: j-users-unsubscribe@xxxxxxxxxxxxxxxxx
> For additional commands, e-mail: j-users-help@xxxxxxxxxxxxxxxxx

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@xxxxxxxxxx
E-mail: mrglavas@xxxxxxxxxx

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xxxxxxxxxxxxxxxxx
For additional commands, e-mail: j-users-help@xxxxxxxxxxxxxxxxx

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