commons-user mailing list archives

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

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

<Root>
  <First>
    <Second AttrName="NewValue" />
  </First>
</Root>

I initialize the JXPathContext using:

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

(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:

<Root>
  <First>
    <Second AttrName="NewValue">
      <Third>foo</Third>
    </Second>
  </First>
</Root>

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
node
	at
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.createPathAndSetValue(JXPathContextReferenceImpl.java:433)
	at
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.createPathAndSetValue(JXPathContextReferenceImpl.java:421)

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,
--Todd

__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message