[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Transmitting XML between different applications


streamresult document
Mukul Gandhi wrote:
> I want to understand the below statement, you have
> written.. "not if you serialize it using the default
> Java object serialization". Is it possible to
> serialize Java DOM objects by some other methods than
> default Java serialization method? How is it
> implemented, and would it make Java DOM objects parser
> neutral?

Mukul,

There are two standard ways to serialise a Java DOM Document.

1. Use the DOM Load & Save facility if your DOM implementation supports 
it, as this is likely to be more efficient:

      http://www.w3.org/TR/DOM-Level-3-LS/

Check whether the implementation supports it as follows:

   Document doc = ...;
   DOMImplementation impl = doc.getImplementation();
   if (impl.hasFeature("LS", "3.0")) {
     DOMImplementationLS ls = (DOMImplementation) impl.getFeature("LS", 
"3.0");
     LSSerializer serializer = ls.createLSSerializer();
     LSOutput output = ls.createLSOutput();
     // configure output ...
     serializer.write(doc, output);
   }

GNU JAXP and Apache Xerces support DOM Load & Save.

2. Use a JAXP identity transformer to serialise to a StreamResult.

   Document doc = ...;
   Transformer identityTransformer = 
TransformerFactory.getInstance().newTransformer();
   DOMSource source = new DOMSource(doc);
   StreamResult result = new StreamResult(...);
   identityTransformer.transform(source, result);

Both these methods serialise to an OutputStream. The resulting stream 
of characters is an XML document. It is as "parser neutral" as any XML 
document - any XML parser parses XML. A DOM Document is not an XML 
document, and is not XML. It is an application-internal representation 
of an XML document in memory. The XML document is the sequence of bytes 
beginning e.g. '<', '?', 'x', 'm', 'l', etc. Use XML as the transfer 
format between different applications.
-- 
Chris Burdess


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.