I am trying to use a single XPath expression to select a node that has a child node which matches another node in the document.
A match would mean that ALL attributes of the node are the same. So if a node was being compared with several attributes doing individual attribute comparisons would be unmaintainable.
As an example given the following:
<Network>
<Machines>
<Machine Name = "MyMachine">
<Services>
<ServiceDetails Description="MyService" Executable="c:\Myservice.exe" DisplayName="My Service" Version="5"/>
</Services>
</Machine>
...
</Machines>
<Services>
<Service Name = "Service1">
<ServiceDetails Description="MyService" Executable="c:\Myservice.exe" DisplayName="My Service" Version="5"/>
</Service>
...
</Services>
</Network>
I want to get the service node from Services based on the ServiceDetails listed under MyMachine.
I thought it would look something like:
//Services/Service[ServiceDetails = //Machines/Machine[@Name='MyMachine']/ServiceDetails]
but it doesn't seem to work. I suspect the '=' operator isn't handling the node comparison correctly. I think there are some XPath 2.0 Methods that might work but I am using .NET 4.0 (System.XML namespace) I do not know if I can use them. If XPath 2.0 methods would help here I would really appreciate an explanation on how to use them in .Net 4.0.
Thanks
<Service>under<Services>by matching the@Descriptionattributes from both<ServiceDetails>? (This would work in that case:/Network/Services/Service[ServiceDetails/@Description = /Network/Machines/Machine[@Name='MyMachine']/Services/ServiceDetails/@Description])