[jdom-interest] Editing Attributes

Rolf Lear jdom at tuis.net
Sun May 13 05:37:48 PDT 2012


You can simply change the value of the Address attribute.

XPathExpression<Element> xp =
XPathFactory.instance().compile("//contact_properties[@user_name='bashiro']",
Filters.element());
Element contactprops = xp.evaluateFirst(document);
contactprops.setAttribute("addess", "newaddress");

Technically you can go direct to the Attribute and do it like:

XPathExpression<Attribute> xp =
XPathFactory.instance().compile("//contact_properties/@address[../@user_name='bashiro']",
Filters.attribute());
Attribute address = xp.evaluateFirst(document);
address.setValue("newaddress");


Rolf


On 13/05/2012 7:08 AM, Bashiro wrote:
> Hello,
>
> I wonder if one has the following in XML file example;
>
> <contact_properties   user_name="bashiro" address="here" phone="3333"
hobby="dGVzdDI" />
>    <contact_properties user_name="test" address="there" phone="444"
hobby="dGVzdDIno" />
>    <contact_properties user_name="test2" address="there 2" phone="4446"
hobby="-dGVzdDIno" />
>
> Username is unique so its the primary  Key.
>
> If I want to edit address of say bashiro, I search for bashiro and when
found,  the address attributes of bashiro is set to the
> new attributes.
> My question is; should the whole bashiro be removed and then the new
attributes set, or one can simply edit only address ?
>
> Bashiro
> Drammen-Norway
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>




More information about the jdom-interest mailing list