Xpath query to find elements which contain a certain descendant

后端 未结 4 411
野性不改
野性不改 2020-12-13 12:39

I\'m using Html Agility Pack to run xpath queries on a web page. I want to find the rows in a table which contain a certain interesting element. In the example below, I wa

相关标签:
4条回答
  • 2020-12-13 13:27

    I know this isn't what the OP was asking, but if you wanted to find an element that had a descendant with a particular attribute, you could do something like this:

    //table[@name='important']/tr[.//*[@attr='value']]
    
    0 讨论(0)
  • 2020-12-13 13:29

    I know it is a late answer but why not going the other way around. Finding all <interestingtag/> tags and then select the parent <tr> tag.

    //interestingtag/ancestor::tr
    
    0 讨论(0)
  • 2020-12-13 13:42

    Actually, you need to look for a descendant, not a child:

    //table[@name='important']/tr[descendant::interestingtag]
    
    0 讨论(0)
  • 2020-12-13 13:45

    "has a descendant named interestintag" is spelled .//interestintag in XPath, so the expression you are looking for is:

    //table[@name='important']/tr[.//interestingtag]
    
    0 讨论(0)
提交回复
热议问题