Select nodes where an attribute contains some sub-text

Discussion in 'XML' started by Duncan, Feb 9, 2006.

  1. Duncan

    Duncan Guest

    Can I use the contains() function within an xpath query to return a
    node whose attribute contains some text?

    Something like: selectNodes("//Dataset[@Pattern contains(@Pattern,
    'xyz')]

    so for the given xml doc

    <root>
    <Datasets>
    <Dataset name="dataset1" Pattern="abc" AnotherAttribute="xyz"/>
    <Dataset name="dataset2" Pattern="xyz" AnotherAttribute="xyz"/>
    <Dataset name="dataset3" Pattern="vwxyz"/>
    </Datasets>
    </root>

    The nodes dataset2 and dataset3 would be returned because their
    'Pattern' attribute contains the text 'xyz'.

    Many thanks,

    Duncan.
    Duncan, Feb 9, 2006
    #1
    1. Advertising

  2. Duncan wrote:

    > Can I use the contains() function within an xpath query to return a
    > node whose attribute contains some text?


    Yes.


    > Something like: selectNodes("//Dataset[@Pattern contains(@Pattern,
    > 'xyz')]


    That is syntactically wrong. A possible XPath expression could be
    /root/Datasets/Dataset[contains(@Pattern, 'xyz')]


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 9, 2006
    #2
    1. Advertising

  3. Duncan

    Duncan Guest

    By jove, it works!

    Thanks,

    Duncan.
    Duncan, Feb 9, 2006
    #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. asd
    Replies:
    3
    Views:
    428
    Arnaud Berger
    May 23, 2005
  2. Xamle Eng

    Why treat text nodes as nodes?

    Xamle Eng, May 13, 2005, in forum: XML
    Replies:
    8
    Views:
    480
    Fredrik Lundh
    May 28, 2005
  3. Replies:
    5
    Views:
    470
    bouton
    Sep 22, 2005
  4. Ben
    Replies:
    2
    Views:
    862
  5. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    1,971
    Lawrence D'Oliveiro
    May 20, 2011
Loading...

Share This Page