Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

xpathAPI- selecting the parent node

Thread view: 
asd - 17 May 2005 12:01 GMT
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
Anton Spaans - 17 May 2005 15:35 GMT
> Hi all,
>
[quoted text clipped - 25 lines]
>
> asd

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

xPath_query = "/messages/message[code='100']";
-- Anton.
Mike Schilling - 08 Jun 2005 23:53 GMT
> Hi all,
>
[quoted text clipped - 18 lines]
> 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::*
asd - 18 Jun 2005 08:04 GMT
Thanks you for all your help


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.