Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Serializing an XML Dom

From: Tjerk Wolterink <tjerk@------------------.--->
To: NULL
Date: 12/1/2005 10:39:00 PM
I have created an W3C XML DOM in java,
it uses namespaces.

Now i want to serialize it to the outputstream:

===
Document document=retrievePageDocument(page, manager.getDataStore());
response.setContentType("text/xml");
PrintWriter out=response.getWriter();
			
DOMSource domSource=new DOMSource(document);
			
StreamResult streamResult=new StreamResult(out);
TransformerFactory tf=TransformerFactory.newInstance();
Transformer serializer=tf.newTransformer();
			serializer.setOutputProperty(OutputKeys.ENCODING,"UTF-8");
			serializer.setOutputProperty(OutputKeys.INDENT, "yes");
			serializer.setOutputProperty(OutputKeys.METHOD, "xml");
serializer.transform(domSource, streamResult);
===

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

I also tried to use the Xerces Serialization API directly:

===
// lets serialize the xml to the output
XMLSerializer serializer=new XMLSerializer(out,
	new OutputFormat(document, "UTF-8", true)
);
serializer.serialize(document);
===

But that also does not inlcude the namespaces??@?

The Document object is namespace aware:

===
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document doc;
doc=factory.newDocumentBuilder().newDocument();
Element root=doc.createElementNS(PAGE_NAMESPACE, "page");
doc.appendChild(root);
===


Pleaz help im stuck here!


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