Seek xpath expression where an attribute name is a regular expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GIMME

    Seek xpath expression where an attribute name is a regular expression

    For starters ....

    If :

    //input[@name='start_da te']

    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!
  • Martin Honnen

    #2
    Re: Seek xpath expression where an attribute name is a regular expression



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

    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]
    [color=blue]
    > 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?[/color]

    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="200 4-01-01" />
    <input date_final="200 4-10-10" />
    <input att="Kibology" />
    <input />
    </root>

    the above XPath selects

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

    Martin Honnen


    Comment

    • GIMME

      #3
      Re: Seek xpath expression where an attribute name is a regular expression

      Thanks Martin.

      This is very helpful.

      Comment

      Working...