Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Serializing an XML Dom

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 12/2/2005 6:31:00 PM

Tjerk Wolterink wrote:

> I have created an W3C XML DOM in java,
> it uses namespaces.

> The serialization works, but it does not include the namespaces!!

The following

       DocumentBuilderFactory documentBuilderFactory = 
DocumentBuilderFactory.newInstance();
       documentBuilderFactory.setNamespaceAware(true);
       DocumentBuilder documentBuilder = 
documentBuilderFactory.newDocumentBuilder();
       Document xmlDocument = 
documentBuilder.getDOMImplementation().createDocument(
         "http://www.w3.org/1999/xhtml",
         "html",
         null
       );
       Element rootElement = xmlDocument.getDocumentElement();
 
rootElement.setAttributeNS("http://www.w3.org/XML/1998/namespace", 
"xml:lang", "en");

       System.out.println("xmlDocument class: " + 
xmlDocument.getClass().getName());
       System.out.println("Serialized document:");
       System.out.println(serializeToString(xmlDocument));

run with Java 1.5 gives

xmlDocument class: com.sun.org.apache.xerces.internal.dom.DocumentImpl
Serialized document:
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"></html>

which looks fine, namespace declarations and prefixes are there.

Run with Java 1.4 however I get:

xmlDocument class: org.apache.crimson.tree.XmlDocument
Serialized document:
<?xml version="1.0" encoding="UTF-8"?>
<html xml:lang="en"/>

so you might have hit a bug with the DOM or Transformer implementation 
you are using respectively which is on your classpath.



-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent