I would like to retrieve all nodes with a node, subnode and subsubnode condition applied
I tried to receive it with this xpath command:
xmlDoc.SelectNodes("//WorkItem[WorkItemType[text()='Product Backlog Item'] and ./Childern/WorkItem/WorkItemType[text() = 'Task'] and /Childern/WorkItem/WorkItemType[text() != 'Product Backlog Item'] and ./Childern/WorkItem/WorkItemType[text() = 'Task']]");
This provides me no nodes. But I expect the WorkItem nodes with Id's: 719 and 720 but NOT 717
How can I express this in XPath?
The given xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<root>
<id>716</id>
<WorkItemType>Product Backlog Item</WorkItemType>
<Children>
<WorkItem>
<id>717</id>
<WorkItemType>Product Backlog Item</WorkItemType>
<Children>
<WorkItem>
<id>719</id>
<WorkItemType>Product Backlog Item</WorkItemType>
<Children>
<WorkItem>
<id>721</id>
<WorkItemType>Task</WorkItemType>
<Children>
<WorkItem>
<id>722</id>
<WorkItemType>Task</WorkItemType>
<Children/>
</WorkItem>
</Children>
</WorkItem>
</Children>
</WorkItem>
<WorkItem>
<id>720</id>
<WorkItemType>Product Backlog Item</WorkItemType>
<TreeLevel>2</TreeLevel>
<Children>
<WorkItem>
<id>724</id>
<WorkItemType>Task</WorkItemType>
<Children>
<WorkItem>
<id>726</id>
<WorkItemType>Task</WorkItemType>
<Children/>
</WorkItem>
</Children>
</WorkItem>
</Children>
</WorkItem>
<WorkItem>
<id>723</id>
<WorkItemType>Task</WorkItemType>
<Children>
<WorkItem>
<id>744</id>
<WorkItemType>Task</WorkItemType>
<Children/>
</WorkItem>
</Children>
</WorkItem>
</Children>
</WorkItem>
</Children>
</root>
Update
Due to Rolf Rander's input I add some more explanation:
- I want to have WorkItem-elements of WorkItemType 'Product Backlog Item' which has ONLY WorkItem-Elements of WorkItemType 'Task' as any kind of children (children, grandchildren grandgrandchildren and so on...).
The level how deep are children capsuled is not clear at design time. I've updated my question. (and I corrected my typo Childern -> Children in the xml file).