How do I write an XPath query to find all nodes containing a specified child where that child doesn't have a specified value

StackOverflow https://stackoverflow.com/questions/17156288

  •  01-06-2022
  •  | 
  •  

Question

I'm looking for an XPath statement to query for all parents that have a specific child where the child's inner text doesn't contain a specified value:

<Project>
  <ItemGroup>
    <Reference Include="NHibernate">
      <HintPath>..\packages\......</HintPath>
    </Reference>
  </ItemGroup>
</Project>

So I want all the reference nodes that have the HintPath child node only where the path specified in the HintPath doesn't start with "..\packages\"

I can already use //x:Reference[x:HintPath] to get the Reference nodes that contain the HintPath node... I just can't figure out the last bit of the chain...

Was it helpful?

Solution

This should work:

//HintPath[not(starts-with(text(),'..\packages\'))]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top