Seek xpath expression where an attribute name is a regular expression

Discussion in 'XML' started by GIMME, Jun 15, 2004.

  1. GIMME

    GIMME Guest

    For starters ....

    If :

    //input[@name='start_date']

    is the xpath syntax to see if an element with an attribute
    named start_date exists ...

    Then what is the xpath syntax to return elements having
    an attribute named '*date*' .

    That is there a way to turn start_date into a regular expression?

    Thanks!
     
    GIMME, Jun 15, 2004
    #1
    1. Advertising

  2. GIMME wrote:

    > For starters ....
    >
    > If :
    >
    > //input[@name='start_date']
    >
    > is the xpath syntax to see if an element with an attribute
    > named start_date exists ...


    No, that expression looks for <input> elements at all levels that have
    an attribute named 'name' that has the value 'start_date'.
    You will be able to look for for elements with an attribute named
    'start_date' with the XPath expression
    //input[@start_date]

    > Then what is the xpath syntax to return elements having
    > an attribute named '*date*' .
    >
    > That is there a way to turn start_date into a regular expression?


    XPath 1.0 doesn't support any regular expressions, there are however
    some string functions like contains so could try
    //input[contains(local-name(@*), 'date')]
    with the example XML being

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <input date="2004-01-01" />
    <input start_date="2004-01-01" />
    <input date_final="2004-10-10" />
    <input att="Kibology" />
    <input />
    </root>

    the above XPath selects

    <input date="2004-01-01" />
    <input start_date="2004-01-01" />
    <input date_final="2004-10-10" />
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 15, 2004
    #2
    1. Advertising

  3. GIMME

    GIMME Guest

    Thanks Martin.

    This is very helpful.
     
    GIMME, Jun 15, 2004
    #3
  4. GIMME

    vforvikash

    Joined:
    Dec 29, 2008
    Messages:
    1
    how to check values with some regular expression

    if i'm having some attributes value like email and i want an xpath with regular expression to check the value?

    how this can be done
     
    vforvikash, Dec 29, 2008
    #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. VSK
    Replies:
    2
    Views:
    2,390
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,527
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Replies:
    2
    Views:
    1,097
    Henry S. Thompson
    Mar 6, 2006
  4. Replies:
    4
    Views:
    545
  5. Replies:
    3
    Views:
    152
    Andreas Perstinger
    May 14, 2013
Loading...

Share This Page