Igor Lobanov <[EMAIL PROTECTED]> wrote on 01/09/2007 10:14:50 PM:

> Thanks, it works. But now I have another problem. Some third-party 
> library generates XML elements, which are added to my XML document. Each 

>   element contains _explicit_ namespace declarations. When document is 
> serialized it looks like I posted earlier (see below). The problem is 
> that even if I add namespace declaration to the top-level element, 
> resulting document looks like this in serialized form:
> 
> <ns:root xmlns:ns="urn:ns1" xmlns:ns2="urn:ns2">
>      <ns2:child xmlns:ns2="urn:ns2"/>
>      <ns2:child xmlns:ns2="urn:ns2"/>
> </ns:root>
> 
> Is there any way to automatically force redunant namespace declarations 
> to be removed from the child elements when they are serialized?

Calling Document.normalizeDocument() with the "namespace-declarations" [1] 
parameter set to false will remove all the namespace declarations from the 
DOM. You could then add back the ones you really wanted and then serialize 
the document. To do this more efficiently you'd have to traverse the DOM 
yourself.

[1] 
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#parameter-namespace-declarations


Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to