Search code examples
xmlxpathapigee

Match <Value> from key-value list (Apigee)


I have the following XML:

<Developer>
  <Attributes>
    <Attribute>
      <Name>Role</Name>
      <Value>xxx</Value>
    </Attribute>   
    <Attribute>
      <Name>CreatedAt</Name>
      <Value>xxx</Value>
    </Attribute>
  </Attributes>
</Developer>

I would like to match the <Value> tag of the <Attribute> whose <Name> is Role

I have tried the following expression (as I read in a SO question about apigee):

/Developer/Attributes/Role

But it isn't working for me. What is the best approach for this?


Solution

  • The segments of an XPath between the slashes are the names of elements. You need to traverse to the elements you want to select from, and then use a predicate to select the right one:

    /Developer/Attributes/Attribute[Name = 'Role']/Value