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!