[jdom-interest] Checking for attributes without namespace in class Element

Alastair Rodgers alastair.rodgers at PHOCIS.COM
Fri Jun 29 02:36:44 PDT 2001


> 
> > 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.  

To me this description does not seem match the b7 source. For the
no-namespace case, taking the code for setAttribute(Attribute attribute) and
trimming out all the namespace-specific code, etc., we are left with: 

    public Element setAttribute(Attribute attribute) {
        boolean preExisting = false;

        if (attributes == null) {
            attributes = new ArrayList(INITIAL_ARRAY_SIZE);
        }
        else if (preExisting) {
            // Remove any pre-existing attribute
            removeAttribute(attribute.getName(), attribute.getNamespace());
        }

        attributes.add(attribute);
        attribute.setParent(this);
        return this;
    }

Surely preExisting should be set appropriately for the no-namespace case?
Otherwise if I do: 

el.setAttribute(new Attribute("blah", "a");
el.setAttribute(new Attribute("blah", "b");

then don't I end up with 2 Attributes with the same name in the attributes
list? 

Al.


The information in this email is confidential and is intended solely for the
addressee(s) and access to this email by anyone else is unauthorised. If you
are not the intended recipient then any disclosure, copying, distribution or
any action taken or omitted to be taken in reliance on it, is prohibited and
may be unlawful. Information expressed in this email are not given or
endorsed by my firm or employer unless otherwise indicated by an authorised
representative independent of this message.



More information about the jdom-interest mailing list