commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Todd Fuller <>
Subject [JXPath] Setting DOM attributes using createPathAndSetValue(...)
Date Tue, 06 Apr 2004 13:52:56 GMT

I'm having some trouble setting attributes in a DOM using
"createPathAndSetValue()" using JXPath v1.1. Starting with a DOM of:

    <Second AttrName="NewValue" />

I initialize the JXPathContext using:

        JXPathContext context = JXPathContext.newContext(rootElem);
        context.setFactory(new JXPathNodeFactory());

(The JXPathNodeFactory creates a new Element from the Document of the
parent Element, and calls parent.appendChild(newElem).)

Running the following:

        context.createPathAndSetValue("/First/Second/Third", "foo");

I get the expected result of:

    <Second AttrName="NewValue">

However, if I run this line to create an attribute on Element "Third"...

        context.createPathAndSetValue("/First/Second/Third/@attr", "foo");

it throws this exception:

org.apache.commons.jxpath.JXPathException: Exception trying to create
xpath /First/Second/Third/@attr; Cannot create an attribute for path
/First[1]/Second[1]/Third/@attr, operation is not allowed for this type of

I guess I'm confused why the expression has enough information to create
the text node, but not enough to set an attribute. Is there something I'm
missing, or are attributes not allowed in a "createPath..." context? I
have tested them with "setValue()", and they work fine.

Thanks in advance,

Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message