SV: [jdom-interest] Strange namespace problem

Per Norrman pernorrman at
Mon Nov 24 14:26:44 PST 2003


I think what Eliotte meant was that in your particular
case, you shouldn't use setNamespace and addNamespaceDeclaration.
There are legitimate uses for both methods. If you call the Element 
constructor or the setAttribute method with the 
namespace argument, the namespace declaration comes for free.

However, your problem was the subsequent customer element, right? The 
question is, what namespace does the customer element belong to?
If it belongs to no namespace, everything is OK, the XML produced is 
valid. <customer xmlns=""> is perfectly valid, as per section 5.2 of the
namespace spec:

If it should belong to another namespace, you must explicitly state
using either the constructor or the setNamespace method (and for the
too, if applicable).


-----Ursprungligt meddelande-----
Från: jdom-interest-admin at [mailto:jdom-interest-admin at]
För Marcel Stör
Skickat: den 24 november 2003 22:23
Till: jdom-interest at
Ämne: RE: [jdom-interest] Strange namespace problem

Elliotte Rusty Harold <mailto:elharo at> wrote:
> At 3:05 PM +0100 11/24/03, Marcel Stor wrote:
>> Hi all,
>> I need to produce the following XML tag:
>> <IT-P_CDB xmlns=""
>> xmlns:xsi=""
>> xsi:schemaLocation="
>>" type="XML">
>> I do this through:
>> Namespace schemaNS = Namespace.getNamespace("xsi",
>> "");
>> Namespace defaultNS = 
>> Namespace.getNamespace("");
>> Element root = new Element("IT-P_CDB"); root.setNamespace(defaultNS);
>> root.addNamespaceDeclaration(schemaNS);
> Don't call setNamespace or addNamespaceDeclaration. The namespaces
> should be passed as arguments to the Element and Attribute 
> constructors.

Oh thanks, that is good to know. Why are those methods part of the API
if they are not supposed to be employed?


To control your jdom-interest membership:

More information about the jdom-interest mailing list