Accessing XML nodes using XPath

  <attribute name="Mail Zone" property="alerts.p45" type="">
  <attribute name="Employee Name" property="acm_alert_custom_attributes.cs11" type="">
  <attribute name="Manager Name" property="alerts.p23" type="">

How can I select the node <value> based on the attribute "name" of the above XML using XPath?


Let's say you wanted to select the value element that is a child of the attribute whose name is "Employee Name".

The XPath expression for that is the following:

/attributes/attribute[@name="Employee Name"]/value

In XSL you can use it like this:

<xsl:value-of select="/attributes/attribute[@name='Employee Name']/value"/>

It's built up the following way. First you want to select a value attribute, whose parent is an attribute element, whose parent is the root (I'm assuming) attributes. The / operator indicates the parent-child relationship between elements. So an expression to select all value elements would be the following:


With that as a base, you want to filter the result by some other attribute. In this case, you want to filter by the name attribute of the attribute element (your choice of names might make things hard to follow). Filtering is done with [] clauses on the elements you want to filter by. In your case that's the attribute element:


Now you need to put something in the filter. The @ symbol indicates attributes of the element you're filtering by, followed by the name of the attribute you want. Then you compare the attribute to some known value, to arrive at the above expression:


Need Your Help

Tools for automating mouse and keyboard events sent to a windows application

testing automation

What tools are useful for automating clicking through a windows form application? Is this even useful? I see the testers at my company doing this a great deal and it seems like a waste of time.