Reputation: 437
Please refer the sample XML below
<Actions>
<Action>
<Name>Forward</Name>
<Value>Forward Assignment</Value>
<panelID>Y0192_pnlForwad</panelID>
<Status>Order Suspended</Status>
<from>Shop</from>
<to>Warehouse</to>
</Action>
</Actions>
If I know the value of "from" node, how can I determine the corresponding value of "Name" and "Value" node using an XPath expression?
Upvotes: 2
Views: 84
Reputation: 243459
If I know the value of "from" node, how can I determine the corresponding value of "Name" and "Value" node using an XPath expression?
Use:
/*/Action[from='Shop']/*[self::Name or self::Value]
This selects any element named Name
or named Value
, whose parent is an Action
child of the top element of the XML document, and (the Action
parent) has a from
child, whose string value is the string "Shop"
.
If you want the Name
and Value
selected (not together but) individually, this can be done evaluting two XPath expressions:
/*/Action[from='Shop']/Name
and
/*/Action[from='Shop']/Value
Upvotes: 1