[jdom-interest] element.setAttribute() ?

Brett McLaughlin brett at newInstance.com
Tue Mar 27 08:44:58 PST 2001


----- Original Message -----
From: "Alex Colic" <alex.colic at pop-ware.com>
To: "JDOM" <jdom-interest at jdom.org>
Sent: Tuesday, March 27, 2001 3:51 PM
Subject: [jdom-interest] element.setAttribute() ?


> Hi
> I am having a problem using the setAttribute method.
>
> Lets say a snippet of my xml file is as follows:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <WorkRequest>
> <Property Required="true">Entity</Property>
> <Property Required="true">Work Title</Property>
>
> How would I go about changing the Required Attribute of the entity element
> to false?

Attribute required = root.getElement("Property").getAttribute("Required");
required.setValue("false");

Of course, that assumes that the Entity one is always the first. If not...

List propertyElements = root.getChildren("Property");
for (Iterator i = propertyElements.iterator(); i.hasNext(); ) {
    Element element = (Element)i.next();
    if (element.getText().equals("Entity")) {
        Attribute attribute = element.getAttribute("Required");
        attribute.setValue("false");
        break;
    }
}

Hope that helps,
Brett

>
> Any help is appreciated.
>
> Regards
>
>
> Alex Colic
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com




More information about the jdom-interest mailing list