dom4j adds default namespace in all elements
843834Sep 24 2008 — edited Sep 25 2008I'm using dom4j to handle XML documents, but I'm having the problem that dom4j adds the default namespace in all child elements.
Consider the following example document:
String xml = "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">"
+ "<list name=\"friends\">"
+ "<entry uri=\"sip:one@test.com\" />"
+ "<entry uri=\"sip:two@test.com\" />"
+ "<entry uri=\"sip:three@test.com\" />"
+ "</list></resource-lists>";
I'm constructing a dom4j Document out of it:
Document dom4jDoc = DocumentHelper.parseText(xml);
(Both Document and DocumentHelper are from package org.dom4j.)
When looking through the dom tree (in debug mode in Eclipse), I can see that dom4j has added the default namespace ("urn:ietf:params:xml:ns:resource-lists" in the example above) in each of the child elements, both the <list> element and the <entry> elements.
Anyone knows how to get around this? It's in conflict with XCAP, rfc4825:
"The server MUST NOT add namespace bindings representing namespaces used by the element or its children, but declared in ancestor elements; the client will either know these bindings already (since it has a cached copy of the whole document), or it can learn them by explicitly querying for the bindings."