[jdom-interest] Checking for attributes without names

stephan.segschneider at snellwilcox.com stephan.segschneider at snellwilcox.com
Thu Jun 28 07:48:09 PDT 2001

____________________Reply Separator____________________
Subject:    RE: [jdom-interest] Checking for attributes without namespac
Author: philip.nelson at omniresources.com
Date:       28/06/01 15:50

> I have just changed my code to work with JDOM beta 7R2. 
> Everything works fine
> but the new setAttribute() method in Element.
> At the moment a checking for an already existing attribute 
> happens only if the
> attribute uses a namespace prefix (see line 1603 in 
> Element.java). I don't think
> that's sensible. In other words, you can't use setAttribute() 
> to update an
> attributes value if you use no namespace prefix. You always 
> need to check inside
> your code if an attribute already exists before you update its value.

The attribute is not updated, it is replaced.  In the case of no namespace,
it can immediately be replaced.  Otherwise there are xml namespace rules
like you can't have two elements with a prefix foo that point to different

You can always update an attributes value without replacing it.

Attribute att = element.getAttribute("name");

Sure, that's what I did before. But you always have to check if the getAttribute
method returns null before you update the value with setValue. The DOM 1.0
Element defines a setAttribute(name, value) method as well which will update the
value if the attribute exists and in case the attribute does not exist it will
automatically create one. I expected the same behaviour for the setAttribute
method in JDOMs Element class.


The contents of this communication are confidential to the normal user of
the email address to which it was sent.  If you have received this email
in error, any use, dissemination, forwarding, printing or copying of this
email is strictly prohibited.  If this is the case, please notify the sender
and delete this message.

More information about the jdom-interest mailing list