Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Serializing an XML Dom [Thread Next] Re: Serializing an XML DomTo: 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/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
