Yasir Khan wrote:
> Writer writer = new Writer(); /*Writer is the class provided in
> Xerces DOM Samples*/
By definition, createElementNS [1] method only creates an element and
never creates a corresponding namespace declaration. Given that neither
Writer nor org.apache.xml.serialize.XMLSerializer by default add missing
namespaces to the DOM tree, you don't see the namespace declaration in
the output.
If you want namespace fixup to take place during serialization, i.e. for
serializer to add missing namespace declarations, use DOM L3 API [2].
One more comment, _never_ mix DOM Level 1 and DOM Level 2 nodes (created
with NS suffix), as you do in your code:
> Element root = doc.createElementNS("http://www.ascertia.com/xml/",
> "myns:root");
> Element element1 = doc.createElement("myns:element1");
That may lead to unpredictable results [3].
[1]
http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030609/core.html#ID-DocCrElNS
[2] http://xml.apache.org/xerces2-j/faq-dom.html#faq-3
[3]
http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030609/core.html#Namespaces-Considerations
Thank you,
--
Elena Litani / IBM Toronto
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]