Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > xpathAPI- selecting the parent node

Reply
Thread Tools

xpathAPI- selecting the parent node

 
 
asd
Guest
Posts: n/a
 
      05-17-2005
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

 
Reply With Quote
 
 
 
 
Anton Spaans
Guest
Posts: n/a
 
      05-17-2005

"asd" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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='100']";
-- Anton.


 
Reply With Quote
 
 
 
 
Mike Schilling
Guest
Posts: n/a
 
      06-08-2005

"asd" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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::*



 
Reply With Quote
 
asd
Guest
Posts: n/a
 
      06-18-2005
Thanks you for all your help

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting the first child node of a parent node ofuuzo1@yahoo.no XML 2 03-17-2008 12:31 PM
Selecting a node with child and parent condition. okaissi79@gmail.com XML 3 09-11-2007 04:52 AM
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
selecting parent node with xpathAPI arvindsd@yahoo.com XML 1 05-17-2005 10:59 AM



Advertisments