xpathAPI- selecting the parent node

A

asd

Hi all,

My XML file is as shown below:

<?xml version="1.0" ?>
<messages>
<message>
<code>100</code>
<text>Unknown application error</text>
</message>
</messages>

My java code:

Element root_element = msg_doc.getDocumentElement();
String xpath_query = "/messages/message/code/text()='100'/parent::*";

NodeList nl=XPathAPI.selectNodeList(root_element, xpath_query);

What I want to do is select the parent node of the "code" node that
contains value 100?
But the code above gives me TransformationException.

Please help me out at the earliest. Thanks in advance for all your
help.

regards,

asd
 
A

Anton Spaans

asd said:
Hi all,

My XML file is as shown below:

<?xml version="1.0" ?>
<messages>
<message>
<code>100</code>
<text>Unknown application error</text>
</message>
</messages>

My java code:

Element root_element = msg_doc.getDocumentElement();
String xpath_query = "/messages/message/code/text()='100'/parent::*";

NodeList nl=XPathAPI.selectNodeList(root_element, xpath_query);

What I want to do is select the parent node of the "code" node that
contains value 100?
But the code above gives me TransformationException.

Please help me out at the earliest. Thanks in advance for all your
help.

regards,

asd

Try this (i have not tested it, though):

xPath_query = "/messages/message
Code:
";
-- Anton.
 
M

Mike Schilling

asd said:
Hi all,

My XML file is as shown below:

<?xml version="1.0" ?>
<messages>
<message>
<code>100</code>
<text>Unknown application error</text>
</message>
</messages>

My java code:

Element root_element = msg_doc.getDocumentElement();
String xpath_query = "/messages/message/code/text()='100'/parent::*";

NodeList nl=XPathAPI.selectNodeList(root_element, xpath_query);

What I want to do is select the parent node of the "code" node that
contains value 100?
But the code above gives me TransformationException.

Yes, the extremely informative "ERROR! Unknown op code: 27" exception. The
string you gave isn't legal XPath, since "text()='100'' is a predicate, not
a step. That is, it chooses a subset of the current set of nodes that
match, rather than proceeding from them to another set of nodes. Predicates
are placed in square brackets. So try this, instead

/messages/message/code[text()='100']/parent::*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,247
Members
46,844
Latest member
JudyGvh32

Latest Threads

Top