XPath expression for element based on content of other element withsame parent

Discussion in 'XML' started by Ian Wilson, Jul 26, 2007.

  1. Ian Wilson

    Ian Wilson Guest

    If I have this XML

    <response>
    <list>
    <item>
    <message>
    <reply>
    <something/>
    <fee>
    <type>A</type>
    <amount>22</amount>
    </fee>
    <fee>
    <type>B</type>
    <amount>98</amount>
    </fee>
    <otherthings/>
    </reply>
    </message>
    </item>
    </list>
    </response>

    Is there an XPath expression I can use to get fee amount 98, i.e. the
    contents of <amount> where <type> contains "B"?
     
    Ian Wilson, Jul 26, 2007
    #1
    1. Advertising

  2. Re: XPath expression for element based on content of other elementwith same parent

    Ian Wilson wrote:
    > If I have this XML
    >
    > <response>
    > <list>
    > <item>
    > <message>
    > <reply>
    > <something/>
    > <fee>
    > <type>A</type>
    > <amount>22</amount>
    > </fee>
    > <fee>
    > <type>B</type>
    > <amount>98</amount>
    > </fee>
    > <otherthings/>
    > </reply>
    > </message>
    > </item>
    > </list>
    > </response>
    >
    > Is there an XPath expression I can use to get fee amount 98, i.e. the
    > contents of <amount> where <type> contains "B"?


    That is easy
    /response/list/item/message/reply/fee[type = 'B']/amount

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jul 26, 2007
    #2
    1. Advertising

  3. Ian Wilson

    Ian Wilson Guest

    Re: XPath expression for element based on content of other elementwith same parent

    Martin Honnen wrote:
    > Ian Wilson wrote:
    >
    >> If I have this XML
    >>
    >> <response>
    >> <list>
    >> <item>
    >> <message>
    >> <reply>
    >> <something/>
    >> <fee>
    >> <type>A</type>
    >> <amount>22</amount>
    >> </fee>
    >> <fee>
    >> <type>B</type>
    >> <amount>98</amount>
    >> </fee>
    >> <otherthings/>
    >> </reply>
    >> </message>
    >> </item>
    >> </list>
    >> </response>
    >>
    >> Is there an XPath expression I can use to get fee amount 98, i.e. the
    >> contents of <amount> where <type> contains "B"?

    >
    >
    > That is easy
    > /response/list/item/message/reply/fee[type = 'B']/amount
    >


    Thanks
     
    Ian Wilson, Jul 26, 2007
    #3
    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. hazz
    Replies:
    6
    Views:
    49,773
    SkyUCHC
    Jun 9, 2010
  2. Anna
    Replies:
    0
    Views:
    541
  3. GIMME
    Replies:
    3
    Views:
    11,997
    vforvikash
    Dec 29, 2008
  4. Daniel Frey
    Replies:
    2
    Views:
    502
    Daniel Frey
    Jan 17, 2005
  5. Oleg Paraschenko
    Replies:
    3
    Views:
    494
    Stefan Ram
    Jul 28, 2006
Loading...

Share This Page