Re: [configuration] XPathExpressionEngine - xpath syntax

2011-12-31 Thread M M

Oliver, thank you very much!
The first hint is working perfectly.

Unfortunately the second change didn't solve the problem, I'm still 
getting null objects although I added the quotes...

I keep on doing tests, maybe I'll find the good syntax.

Thank you very much again!
Bye
MM



On 29/12/2011 21.27, Oliver Heger wrote:

Hi, some comments below...

Oliver

Am 29.12.2011 11:02, schrieb M M:

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:




test project 1
test project 2
test project 3















1
2


1
2




















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 testList001 =
configurationFile.getList(/"permissions/allowed-projects/project[@id]"/); 


for (Iterator 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 testList002 =
configurationFile.getList(/"permissions/allowed-projects/project[@id]"/); 


for (Iterator iterator = testList002.iterator();
iterator.hasNext();)
{
System.out.println(iterator.next());
}


Try the key "permissions/allowed-projects/project/@id"; the square 
brackets are not needed for accessing attributes.




*// 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 testList003 =
configurationFile.getList(/"kpi-definition/project[@id=10020]/issue-type[@id=1]/transition"/); 



for (Iterator iterator = testList003.iterator();
iterator.hasNext();)
{
System.out.println(iterator.next());
}


For this and the following example it may be necessary to quote the 
values because they are strings, e.g.

"kpi-definition/project[@id='10020']/issue-type[@id='1']/transition"



*// 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





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




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



Re: [configuration] XPathExpressionEngine - xpath syntax

2011-12-29 Thread Oliver Heger

Hi, some comments below...

Oliver

Am 29.12.2011 11:02, schrieb M M:

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:




test project 1
test project 2
test project 3















1
2


1
2




















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 testList001 =
configurationFile.getList(/"permissions/allowed-projects/project[@id]"/);
for (Iterator 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 testList002 =
configurationFile.getList(/"permissions/allowed-projects/project[@id]"/);
for (Iterator iterator = testList002.iterator();
iterator.hasNext();)
{
System.out.println(iterator.next());
}


Try the key "permissions/allowed-projects/project/@id"; the square 
brackets are not needed for accessing attributes.




*// 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 testList003 =
configurationFile.getList(/"kpi-definition/project[@id=10020]/issue-type[@id=1]/transition"/);

for (Iterator iterator = testList003.iterator();
iterator.hasNext();)
{
System.out.println(iterator.next());
}


For this and the following example it may be necessary to quote the 
values because they are strings, e.g.

"kpi-definition/project[@id='10020']/issue-type[@id='1']/transition"



*// 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





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



[configuration] XPathExpressionEngine - xpath syntax

2011-12-29 Thread M M
 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:




test project 1
test project 2
test project 3















1
2


1
2




















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 testList001 = 
configurationFile.getList(/"permissions/allowed-projects/project[@id]"/);
for (Iterator 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 testList002 = 
configurationFile.getList(/"permissions/allowed-projects/project[@id]"/);
for (Iterator 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 testList003 = 
configurationFile.getList(/"kpi-definition/project[@id=10020]/issue-type[@id=1]/transition"/);
for (Iterator 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