Search code examples
xpath

how do i add a comment to an xpath?


for example i have an xpath and wish to add a comment near it to identify it.

/html/body/div/table/tr/td/a{this is a link}

Solution

  • Not a comment syntax, but you can give string literals as predicate, which evaluates as true (imho) and should not change the outcome of the expression. I don't know if this has big performance drawbacks.

    /html/body/div/table["this is"]["a table"]/tr/td/a["this is a link"]
    

    But like mjv said, I also would stick to the syntax of the host language.