You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by ro...@novosoft.ru on 2003/04/17 11:51:06 UTC

Duplicate xmlns attribute

Hello,
I want to find out how to avoid duplication of xmlns attribute in the root node of XML document
while serializing it to XML file.

The problem is the following:

1 I request a DOMImplementation instance from Xerces.
2 Then I create a document with it and specify a qualified tag name and namespace URI.
3 After serializing this document to xml-file, under some versions of Xerces I get the correct
document with "xmlns:prefix" attribute in the root and under other versions of Xerces this attribute
is absent.
4 If I manually insert this attribute with the setAttribute method, the Xerces serializes it twice
in the first case and once in the last case.

This is a fragment of code on which I have this bug:

DOMImplementation impl = new DOMImplementationImpl();
Document doc = impl.createDocument("http://www.w3.org/1999/XSL/Transform", "xsl:stylesheet", null);
Element root = doc.getDocumentElement();
root.setAttribute("xmlns:xsl", "http://www.w3.org/1999/XSL/Transform");

After serializing this code under Xerces 1.2.3 and some other versions the document is correct,
but after serializing under Xerces 2.0.1 (and some others) the "xmlns:xsl" attribute is duplicated.
If I comment the last line, this attribute dissapears under Xerces 1.2.3 and the duplication also
dissapears under Xerces 2.0.1.

What is the right behaviour and what version produces a bug?
Seems the bug is in the createElementNS item. How to overcome this bug and find a workaround which
will work under any Xerces and any other non-Xerces implementation?

If I create a document directly using Xerces-specific methods I can easy overcome this problem. But
it is not interested for me because of dependency on DOM implementation. I need as independent way
as possible. For this I want to use the DOMImplementation object for constructing documents. But
this way is also bad because depends on Xerces version.

Sincerely,
Alexander I Rozhenko,
Developer,
Novosoft, STO Department
Custom software development and web design since 1992

Phone: +7 (3832) 33-36-49
Fax: +7 (3832) 39-63-58
mailto:roj@novosoft.ru
For more visit http://www.novosoft-usa.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Duplicate xmlns attribute

Posted by Elena Litani <el...@ca.ibm.com>.

roj@novosoft.ru wrote:
> 1 I request a DOMImplementation instance from Xerces.
> 2 Then I create a document with it and specify a qualified tag name and namespace URI.
> 3 After serializing this document to xml-file, under some versions of Xerces I get the correct
> document with "xmlns:prefix" attribute in the root and under other versions of Xerces this attribute
> is absent.
> 4 If I manually insert this attribute with the setAttribute method, the Xerces serializes it twice
> in the first case and once in the last case.


Looks like a bug to me. Please, check if you see the same behavior in
Xerces 4.2.0 -- I suspect it was already fixed. The namespaces are no
longer fixed by default in XMLSerializer. To force serializer to do the
fixup you need to either call setNamespace on XMLSerializer or use
DOMWriter (DOM Level 3).

Thanks,
-- 
Elena Litani / IBM Toronto

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org