Hey guys,
Couldn't find what I'm looking for, so trying to see if anybody has worked with Apache Commons XML Configuration.
I can read attributes and nodes by name just fine, what I was looking for was a look-up function by ID.
SO
If you have a String str = "456", how do you make XMLConfiguratio n class give you the second node in this example without getting all the id's and looping through it (which is what I'm currently doing).
Desired Code:
Thanks!
Dan
Couldn't find what I'm looking for, so trying to see if anybody has worked with Apache Commons XML Configuration.
I can read attributes and nodes by name just fine, what I was looking for was a look-up function by ID.
SO
Code:
<nodes> <node id="123" foo="bar1">test1</node> <node id="456" foo="bar2">test2</node> </nodes>
Desired Code:
Code:
String str = "456";
XMLConfiguration config = new XMLConfiguration("config.xml");
config.setExpressEngine(new XPathExpressionEngine());
HierarchicalConfiguration node = (HierarchicalConfiguration) config.getNodeByID(str);
String foo = node.getString("[@foo]");
System.out.println(foo);
/**
Ouputs:
bar2
*/
Dan
Comment