selecting parent node with xpathAPI

Discussion in 'XML' started by arvindsd@yahoo.com, May 17, 2005.

  1. Guest

    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
     
    , May 17, 2005
    #1
    1. Advertising

  2. wrote:


    > 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);


    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/
     
    Martin Honnen, May 17, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,616
  2. asd
    Replies:
    3
    Views:
    641
  3. Scott Simpson
    Replies:
    2
    Views:
    631
    Scott Simpson
    Jun 10, 2005
  4. David  Portabella
    Replies:
    2
    Views:
    595
    David Portabella
    Aug 27, 2007
  5. Replies:
    3
    Views:
    438
Loading...

Share This Page