regex xpath expressions

Discussion in 'XML' started by Timo Nentwig, Feb 1, 2004.

  1. Timo Nentwig

    Timo Nentwig Guest

    Hi!

    Seems that * cannot stand for non-existing nodes, i.e.

    /html/*/title

    will not match

    <html>
    <title>won't match</title>
    </html>

    Isn't it possible to write a xpath that will match the above as well as
    <title> encapsulated in <head> (except exp1 | exp2 | expN)?

    Regards,
    Timo
    Timo Nentwig, Feb 1, 2004
    #1
    1. Advertising

  2. "Timo Nentwig" <> wrote in message
    news:bvjhgc$ssfp7$-berlin.de...
    > Hi!
    >
    > Seems that * cannot stand for non-existing nodes, i.e.


    Of course not. It would save time to read a good text in XPath before asking
    such kind of questions.

    >
    > /html/*/title
    >
    > will not match


    An XPath expression does not "match" -- it selects.

    >
    > <html>
    > <title>won't match</title>
    > </html>
    >
    > Isn't it possible to write a xpath that will match the above as well as
    > <title> encapsulated in <head> (except exp1 | exp2 | expN)?



    The above is not well-formed xml.

    What do you mean?


    Dimitre Novatchev [XML MVP],
    FXSL developer, XML Insider,

    http://fxsl.sourceforge.net/ -- the home of FXSL
    Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
    Dimitre Novatchev, Feb 1, 2004
    #2
    1. Advertising

  3. Timo Nentwig

    Timo Nentwig Guest

    Dimitre Novatchev wrote:

    > The above is not well-formed xml.


    Sure it is. But this doesn't matter anyway.

    > What do you mean?


    I want one xpath that will select <td> in both cases:

    <table>
    <tbody>
    <tr><td>...
    </tbody>
    </table>

    <table>
    <tr><td>...
    </table>
    Timo Nentwig, Feb 2, 2004
    #3
  4. Timo Nentwig

    Mats Kindahl Guest

    Timo Nentwig <> writes:

    > Dimitre Novatchev wrote:
    >
    > > The above is not well-formed xml.

    >
    > Sure it is. But this doesn't matter anyway.
    >
    > > What do you mean?

    >
    > I want one xpath that will select <td> in both cases:
    >
    > <table>
    > <tbody>
    > <tr><td>...
    > </tbody>
    > </table>
    >
    > <table>
    > <tr><td>...
    > </table>


    The XPath expression 'table//td' will match any 'td' with a
    'table' node as ancestor.

    Best wishes,
    Mats Kindahl
    --
    IAR Systems in Uppsala, Sweden.

    Any opinions expressed are my own and not those of my company.

    Spam prevention: contact me at or
    , removing the *NO SPAM* from the address.
    Mats Kindahl, Feb 2, 2004
    #4
  5. "Timo Nentwig" <> wrote in message news:bvl7oq$ttrfg$-berlin.de...
    > Dimitre Novatchev wrote:
    >
    > > The above is not well-formed xml.

    >
    > Sure it is. But this doesn't matter anyway.


    That certainly matters!

    >
    > > What do you mean?

    >
    > I want one xpath that will select <td> in both cases:
    >
    > <table>
    > <tbody>
    > <tr><td>...
    > </tbody>
    > </table>
    >
    > <table>
    > <tr><td>...
    > </table>




    These are not well-formed xml documents.

    An XPath expression can only be evaluated against a well-formed xml
    document.

    Unless you provide such, your question has no meaning.

    So I have to guess what would be the well-formed xml document you had
    in mind.

    In case you meant:

    <table>
    <tbody>
    <tr><td/></tr>
    </tbody>
    </table>

    and

    <table>
    <tr><td/></tr>
    </table>


    Then one XPath expression (there are many!) thatselects the "td"
    element in both cases is:

    /table/td | /table/tr/td


    Cheers,

    Dimitre Novatchev [XML MVP],
    FXSL developer, XML Insider,

    http://fxsl.sourceforge.net/ -- the home of FXSL
    Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
    Dimitre Novatchev, Feb 2, 2004
    #5
    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. Jay Douglas
    Replies:
    0
    Views:
    600
    Jay Douglas
    Aug 15, 2003
  2. Thor W Hammer
    Replies:
    0
    Views:
    1,758
    Thor W Hammer
    Mar 14, 2006
  3. Tjerk Wolterink

    XPath: efficiency in xpath expressions

    Tjerk Wolterink, Nov 13, 2004, in forum: XML
    Replies:
    1
    Views:
    1,626
    Richard Tobin
    Nov 13, 2004
  4. Replies:
    3
    Views:
    757
    Reedick, Andrew
    Jul 1, 2008
  5. Noman Shapiro
    Replies:
    0
    Views:
    232
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page