OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Transmitting XML between different applications

[ Lists Home | Date Index | Thread Index ]

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





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS