You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Erik Engstrom <ee...@l1id.com> on 2008/05/14 05:41:46 UTC

[configuration] XPathExpressionEngine inconsistency in setProperty/addProperty

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?

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.

Thanks for your time,

Erik

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


Re: [configuration] XPathExpressionEngine inconsistency in setProperty/addProperty

Posted by Erik Engstrom <es...@gmail.com>.
Thanks, for your answer, this is what I was starting to believe.   What was
throwing me off is that I CAN add an attribute with setProperty to the root
node, just not to child nodes.

Erik


On Wed, May 14, 2008 at 3:22 PM, Oliver Heger <ol...@oliver-heger.de>
wrote:

> 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
> Oliver
>
> [1] http://commons.apache.org/configuration/issue-tracking.html
>
>
>
>> Thanks for your time,
>>
>> Erik
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [configuration] XPathExpressionEngine inconsistency in setProperty/addProperty

Posted by Oliver Heger <ol...@oliver-heger.de>.
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
Oliver

[1] http://commons.apache.org/configuration/issue-tracking.html

> 
> Thanks for your time,
> 
> Erik
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


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