xpathAPI- selecting the parent node

Discussion in 'Java' started by asd, May 17, 2005.

  1. asd

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

  2. asd

    Anton Spaans Guest

    "asd" <> wrote in message
    news:...
    > 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.
     
    Anton Spaans, May 17, 2005
    #2
    1. Advertising

  3. "asd" <> wrote in message
    news:...
    > 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::*
     
    Mike Schilling, Jun 8, 2005
    #3
  4. asd

    asd Guest

    Thanks you for all your help
     
    asd, Jun 18, 2005
    #4
    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,496
  2. Replies:
    1
    Views:
    492
    Martin Honnen
    May 17, 2005
  3. Scott Simpson
    Replies:
    2
    Views:
    624
    Scott Simpson
    Jun 10, 2005
  4. David  Portabella
    Replies:
    2
    Views:
    589
    David Portabella
    Aug 27, 2007
  5. Replies:
    3
    Views:
    433
Loading...

Share This Page