SV: [jdom-interest] Strange namespace problem

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


Hi,

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: http://www.w3.org/TR/REC-xml-names/#defaulting.

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

/pmn



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


Elliotte Rusty Harold <mailto:elharo at metalab.unc.edu> 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="http://www.it-p.ch/namespace"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="http://www.it-p.ch/namespace
>> http://www.praut.com/CDB.xsd" type="XML">
>> 
>> I do this through:
>> Namespace schemaNS = Namespace.getNamespace("xsi",
>> "http://www.w3.org/2001/XMLSchema-instance");
>> Namespace defaultNS = 
>> Namespace.getNamespace("http://www.it-p.ch/namespace");
>> 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?

Regards,
Marcel

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@you
rhost.com




More information about the jdom-interest mailing list