commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From M M <s.rogers.1...@gmail.com>
Subject [configuration] XPathExpressionEngine - xpath syntax
Date Thu, 29 Dec 2011 10:02:18 GMT
  Hi, I'm trying to use /_*Commons Configuration*_/ to parse an XML 
configuration file and I'm having some troubles with the xpath syntax.
After a few tries I understood that I need to use the 
XPathExpressionEngine, and i think that the problems I'm facing are due 
to the xpath syntax I'm using.

Here is the xml file:
------------------------------------------------------------------------
<general-configuration>
<permissions>
<allowed-projects>
<project id="10020" key="TP1">test project 1</project>
<project id="10021" key="TP2">test project 2</project>
<project id="10022" key="TP3">test project 3</project>
</allowed-projects>

<allowed-groups>
<group id="xyz" name="test group"/>
</allowed-groups>

<allowed-users>
<user id="zxy" name="test user"/>
</allowed-users>
</permissions>

<kpi-definition>
<project id="10020" key="DP">
<issue-type id="1" name="Bug">
<kpi id="1" name="t0 - t1" days="0" hours="0" minutes="10">
<transition id="1" name="a">1</transition>
<transition id="2" name="b">2</transition>
</kpi>
<kpi id="2" name="t1 - t2" days="0" hours="1" minutes="0">
<transition id="3" name="c">1</transition>
<transition id="4" name="d">2</transition>
</kpi>
</issue-type>

<issue-type id="3" name="Task">

<kpi id="1" name="t0 - t1" days="0" hours="0" minutes="10">
<transition id="5" name="e"></transition>
<transition id="6" name="f"></transition>
</kpi>

<kpi id="2" name="t1 - t2" days="0" hours="1" minutes="0">
<transition id="7" name="g"></transition>
<transition id="8" name="h"></transition>
</kpi>
</issue-type>
</project>
</kpi-definition>
</general-configuration>
------------------------------------------------------------------------

And here is the code I wrote to try to understand how to get what i want 
using the XPathExpressionEngine
------------------------------------------------------------------------
private XMLConfiguration configurationFile;

configurationFile = new XMLConfiguration(/"kpi_configuration.xml"/);
configurationFile.setExpressionEngine(new XPathExpressionEngine());


DefaultExpressionEngine defaultEngine = new DefaultExpressionEngine();
defaultEngine.setPropertyDelimiter(/"/"/);
configurationFile.setExpressionEngine(defaultEngine);

*// using the default expression engine i get what i want, a list of the
// "id" attributes of the project tag (10020,10021,10022)*
List<String> testList001 = 
configurationFile.getList(/"permissions/allowed-projects/project[@id]"/);
for (Iterator<String> iterator = testList001.iterator(); 
iterator.hasNext();)
{
     System.out.println(iterator.next());
}

configurationFile.setExpressionEngine(new XPathExpressionEngine());
*// using the xpath expression engine, and giving exactly the same path 
to the getList method
// i get a completely different result! the list is made of the text 
content of the tag
// (test project 1, test project 2, test project 3)*
List<String> testList002 = 
configurationFile.getList(/"permissions/allowed-projects/project[@id]"/);
for (Iterator<String> iterator = testList002.iterator(); 
iterator.hasNext();)
{
     System.out.println(iterator.next());
}

*// here I tried to use the xpath syntax [@attribute=value] to get into 
a specific branch of the xml tree
// the expected result was at least a list of values, instead i get null 
object*
List<String> testList003 = 
configurationFile.getList(/"kpi-definition/project[@id=10020]/issue-type[@id=1]/transition"/);
for (Iterator<String> iterator = testList003.iterator(); 
iterator.hasNext();)
{
     System.out.println(iterator.next());
}

*// here I tried to use the xpath syntax [@attribute=value] to get into 
a specific branch of the xml tree
// the expected result was a single value instead i got a null object*
String testValue001 = 
configurationFile.getString(/"kpi-definition/project[@id=10020]/issue-type[@id=1]/transition[@name=a]"/);
System.out.println(testValue001);

Many, many thanks in advance to everyone who can help me!
I really can't work it out (... and I have to :) ... )
MM


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message