commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <>
Subject Re: [configuration] XPathExpressionEngine inconsistency in setProperty/addProperty
Date Wed, 14 May 2008 20:22:37 GMT
Erik Engstrom schrieb:
> Hello, thanks for the great product.  I have been using
> commons-configuration for some time but am new to the
> XPathExpressionEngine and am having trouble figuring out how to use it
> properly.
> I am trying to use the XPathExpressionEngine to populate a new
> XMLConfiguration using commons-configuration-1.5.  It seems that
> setProperty will create a new attribute for the root but not for child
> nodes.
> Can you please explain why the following works:
> XMLConfiguration config = new XMLConfiguration();
> config.setExpressionEngine(new XPathExpressionEngine());
> config.setProperty("/ @version", "1.0");
> but if I add a child node to the root and then try to add a new
> attribute to the child using setProperty it fails:
> config.setProperty("/ child", "");
> config.setProperty("/child @name", "child0");  //Fails with
> "org.apache.commons.jxpath.JXPathException: Invalid XPath: '/child
> @name'. Syntax error after: '/c'"
> If I change the last call to setProperty to addProperty the new
> attribute is created and after that I can call setProperty with out
> getting an exception.
> Is this a bug, or do I not understand how this should work?
Indeed the setProperty() method works differently and does not support 
the extended syntax for adding new properties. I updated the Javadocs 
for XPathExpressionEngine to make this clear.

> I also expected to be able to create the child node and the attribute
> with one call like:
> config.setProperty("/ child/@name", "child0"); //Fails with
> java.lang.IllegalArgumentException: Invalid node path: "child/@name"
> contains an attribute delimiter at an unallowed position.
The syntax for declaring complete paths is not exactly conform to XPATH. 
Try config.setProperty("/ child@name", "child0") instead (i.e. remove 
the slash before the @). Maybe this should be changed to be closer to 
XPATH. If you think it is worth, you can create a ticket in our bug 
tracking system [1].



> Thanks for your time,
> Erik
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message