[jdom-interest] removing namespace

Gordon Tyler Gordon.Tyler at quest.com
Wed Mar 10 13:43:32 PST 2004


Martin Smith wrote:
> I am only removing the namespace from the <Reference> element, and
> this is the only place it appears, so I don't think that the
> namespace is applicable to any parent.  
> 
> <ns1:Reference
>
xmlns:ns1="http://www.govtalk.gov.uk/gateway/digitalmail">PRG278</ns1:Re
ference>

Try this:

    // Either:
    Namespace rootns =
Namespace.getNamespace("http://www.govtalk.gov.uk/taxation/CodingNoticeP
9");
    // or:
    Namespace rootns = myRootElement.getNamespace();
    
    Namespace ns1 = Namespace.getNameSpace("ns1",
"http://www.govtalk.gov.uk/gateway/digitalmail");
    Element ref = parent.getChild("Reference", ns1);
    ref.setNamespace(rootns);

The trick here is not that you want the Reference element to have no
namespace but rather that you want it to be in the same namespace as its
parent, which turns out to be the default namespace set on the root
element.

Ciao,
Gordon



More information about the jdom-interest mailing list