You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by bnreddy <na...@gmail.com> on 2009/03/25 16:44:16 UTC

Commons XMLConfiguration Issue --XPath query with /root

Hi All,
    I am a newbie and was looking into the commons config with
XPathExpressionEngine 

   config.getProperty("/root/fchild/name") is returning  a null but
config.getProperty("fchild/Name") is working fine.... /root/fchild/name is a
valid XPath query and not sure where I am going wrong....can you please let
me know what needs to be fixed here....



import java.net.URL;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;

public class TestClass {
	public static Configuration config = null;
       static {
		init();
	}
	public static void init() {
		try {
			URL url = TestClass.class.getClassLoader().getResource("config/abc.xml");
			XMLConfiguration configuration = new XMLConfiguration();
			configuration.setExpressionEngine(new XPathExpressionEngine());
			configuration.setURL(url);
			configuration.load(url);
			config = configuration;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String [] args) {
		System.out.println(config.getProperty("/root/fchild/name"));
	}
}



abc.xml ;;;


<?xml version="1.0" encoding="UTF-8"?>
<root>
	<fchild>
		<name>Name</name>
		<id>1</id>
		<descriptor>Name Id relation</descriptor>
		<schild>
			<version>2</version>
			<num>2.333</num>
		</schild>
	</fchild>
</root>
-- 
View this message in context: http://www.nabble.com/Commons-XMLConfiguration-Issue---XPath-query-with--root-tp22704510p22704510.html
Sent from the Commons - User mailing list archive at Nabble.com.


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


Re: Commons XMLConfiguration Issue --XPath query with /root

Posted by bnreddy <na...@gmail.com>.
Thanks Oliver for clarifying this.... 


Oliver Heger-3 wrote:
> 
> bnreddy schrieb:
>> Hi christian,
>> 
>>     From my understanding (correct me if I am wrong)... "The root element
>> is
>> ignored when constructing keys". but this is when XMLConfiguration is
>> using
>> DefaultExpressionEngine....
>> 
>>    Is root element ignored even when the XPathExpressionEngine is being
>> used
>> by XMLConfig...
>> 
>>   The problem is ...there are preexisting XPaths and we need to fit this
>> in
>> that...
>> 
>>   as per shouldn't the XMLConfiguration be able to support all legal
>> XPath's
>> instead of trimming root elements...
> 
> XMLConfiguration used to ignore the root element from the very 
> beginning. Expression engines were introduces later, but when the 
> refactoring was done this behavior was not changed to remain backwards 
> compatible.
> 
> When XPathExpressionEngine was implemented it seems only natural to 
> mimic the behavior of DefaultExpressionEngine to be consistent.
> 
> Oliver
> 
>> 
>> 
>> 
>> this is noted in the user guide: XPathExpressionEngine expressions
>> ignore the root element - so just leave it away. What problems could
>> arise from this?
>> 
>> christian!
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Commons-XMLConfiguration-Issue---XPath-query-with--root-tp22704510p22723428.html
Sent from the Commons - User mailing list archive at Nabble.com.


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


Re: Commons XMLConfiguration Issue --XPath query with /root

Posted by Oliver Heger <ol...@oliver-heger.de>.
bnreddy schrieb:
> Hi christian,
> 
>     From my understanding (correct me if I am wrong)... "The root element is
> ignored when constructing keys". but this is when XMLConfiguration is using
> DefaultExpressionEngine....
> 
>    Is root element ignored even when the XPathExpressionEngine is being used
> by XMLConfig...
> 
>   The problem is ...there are preexisting XPaths and we need to fit this in
> that...
> 
>   as per shouldn't the XMLConfiguration be able to support all legal XPath's
> instead of trimming root elements...

XMLConfiguration used to ignore the root element from the very 
beginning. Expression engines were introduces later, but when the 
refactoring was done this behavior was not changed to remain backwards 
compatible.

When XPathExpressionEngine was implemented it seems only natural to 
mimic the behavior of DefaultExpressionEngine to be consistent.

Oliver

> 
> 
> 
> this is noted in the user guide: XPathExpressionEngine expressions
> ignore the root element - so just leave it away. What problems could
> arise from this?
> 
> christian!
> 


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


Re: Commons XMLConfiguration Issue --XPath query with /root

Posted by bnreddy <na...@gmail.com>.
Hi christian,

    From my understanding (correct me if I am wrong)... "The root element is
ignored when constructing keys". but this is when XMLConfiguration is using
DefaultExpressionEngine....

   Is root element ignored even when the XPathExpressionEngine is being used
by XMLConfig...

  The problem is ...there are preexisting XPaths and we need to fit this in
that...

  as per shouldn't the XMLConfiguration be able to support all legal XPath's
instead of trimming root elements...



this is noted in the user guide: XPathExpressionEngine expressions
ignore the root element - so just leave it away. What problems could
arise from this?

christian!

-- 
View this message in context: http://www.nabble.com/Commons-XMLConfiguration-Issue---XPath-query-with--root-tp22704510p22707189.html
Sent from the Commons - User mailing list archive at Nabble.com.


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


Re: Commons XMLConfiguration Issue --XPath query with /root

Posted by Christian Migowski <ch...@gmail.com>.
this is noted in the user guide: XPathExpressionEngine expressions
ignore the root element - so just leave it away. What problems could
arise from this?

christian!

On Wed, Mar 25, 2009 at 4:44 PM, bnreddy <na...@gmail.com> wrote:
>
> Hi All,
>    I am a newbie and was looking into the commons config with
> XPathExpressionEngine
>
>   config.getProperty("/root/fchild/name") is returning  a null but
> config.getProperty("fchild/Name") is working fine.... /root/fchild/name is a
> valid XPath query and not sure where I am going wrong....can you please let
> me know what needs to be fixed here....
>
>
>
> import java.net.URL;
> import org.apache.commons.configuration.Configuration;
> import org.apache.commons.configuration.XMLConfiguration;
> import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
>
> public class TestClass {
>        public static Configuration config = null;
>       static {
>                init();
>        }
>        public static void init() {
>                try {
>                        URL url = TestClass.class.getClassLoader().getResource("config/abc.xml");
>                        XMLConfiguration configuration = new XMLConfiguration();
>                        configuration.setExpressionEngine(new XPathExpressionEngine());
>                        configuration.setURL(url);
>                        configuration.load(url);
>                        config = configuration;
>                } catch (Exception e) {
>                        e.printStackTrace();
>                }
>        }
>
>        public static void main(String [] args) {
>                System.out.println(config.getProperty("/root/fchild/name"));
>        }
> }
>
>
>
> abc.xml ;;;
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
>        <fchild>
>                <name>Name</name>
>                <id>1</id>
>                <descriptor>Name Id relation</descriptor>
>                <schild>
>                        <version>2</version>
>                        <num>2.333</num>
>                </schild>
>        </fchild>
> </root>
> --
> View this message in context: http://www.nabble.com/Commons-XMLConfiguration-Issue---XPath-query-with--root-tp22704510p22704510.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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