Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 09:38 AM
arvindsd@yahoo.com
Guest
 
Posts: n/a
Default selecting parent node with xpathAPI

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

  #2  
Old July 20th, 2005, 09:38 AM
Martin Honnen
Guest
 
Posts: n/a
Default Re: selecting parent node with xpathAPI



arvindsd@yahoo.com wrote:

[color=blue]
> 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);[/color]

If the XPath is relative to the document element then you need
message[code = '100']
For an absolute XPath you need
/messages/message[code = '100']

--

Martin Honnen
http://JavaScript.FAQTs.com/
 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles