Use ser.serialize(doc.getDocumentElement()) instead.
-Lei
-----Original Message-----
From: Julian Reschke [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 08, 2001 3:46 PM
To: [EMAIL PROTECTED]
Subject: Serialization problems
Hi,
I'm trying to serialize a document that has been built using the DOM-Level-2
namespace aware methods:
public static void main(String[] args)
throws java.io.IOException {
main main1 = new main();
Document doc = new org.apache.xerces.dom.DocumentImpl ();
Element root = doc.createElementNS ("ns1", "bar");
doc.appendChild (root);
root.setAttributeNS ("ns2", "attr", "val");
org.apache.xml.serialize.OutputFormat of =
new org.apache.xml.serialize.OutputFormat (doc, null, true);
java.io.StringWriter out = new java.io.StringWriter();
org.apache.xml.serialize.XMLSerializer ser =
new org.apache.xml.serialize.XMLSerializer(out, of);
ser.serialize (doc);
System.out.println (out.toString());
}
The result is:
<?xml version="1.0" ?>
<bar attr="val"/>
However, this is clearly wrong, it should be something like:
<?xml version="1.0" ?>
<bar xmlns="ns1" prefix:attr="val" xmlns:prefix="ns2" />
I reported the problem three months ago, but received no feedback:
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=596>.
Is there something wrong with my code, or does the serializer indeed not
able to serialize namespace declarations properly? I find this surprising
because the changelog for XMLSerializer.java shows that there have been
fixes applied regarding namespace handling.
Any feedback appreciated,
Julian
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
