commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bnreddy <naveen.red...@gmail.com>
Subject Commons XMLConfiguration Issue --XPath query with /root
Date Wed, 25 Mar 2009 15:44:16 GMT

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


Mime
View raw message