Select a node with XPath whose child node contains a specific inner text

后端 未结 4 1730
小鲜肉
小鲜肉 2021-02-14 03:14

Given the following XML:


    
  • abcText1cba
  • abcText2cba
  • 4条回答
    •  暖寄归人
      2021-02-14 03:39

      Your current xpath should be correct. Here is an alternative but ugly one.

      XmlNodeList nodes = doc.SelectNodes("//span/parent::li/span[contains(text(), 'Text1')]/parent::li");
      

      We find all the span-tags. Then we find all the li-tags that has a span-tag as child and contains the 'Text1'.

      OR simply:

      //span[contains(text(), 'Text1')]/parent::li

    提交回复
    热议问题