How to read XML Attribute value from XML message in API Gateway? Want to read value of uniqueRequestId in below XML:
You can accomplish this via 'XPATH'. We have a few assertions in our Assertion Palette that should be able to meet your needs. ( Evaluate Request Xpath, Evaluate Response Xpath)
If you are wanting to extract data from the Request context, you will need to use the first one mentioned above.
If you are wanting to extract data from the Response context or from a variable in policy, you will need to use the 'Evaluate Response Xpath'.
Here's a simple policy that does this.
I store my xml in a variable in this case ( i could target the Request or the Response directly as well ).
i then use the 'Evaluate Response Xpath' assertion to target my Message Variable called 'meMessage'.
This is what the Assertion properties look like... I made sure i set my 'Source' and Prefix.
for building the path, you can use the 'Sample Messages' at the bottom of the assertion to help, but it will only get you 90% of the way there in your case... you have to know how to get the rest of the 10% if this isn't an easy xpath.. in your case, to target an attribute, you'll need the '@'.
the assertion sets a few variables after it runs, you can view what variables an assertion sets by hovering you mouse over it.. like below
we are interested in the <prefix>.result variable, so in our Return Template, we echo this back and this guy returns the attribute that matched our xpath.
hope this helped.
You need to use Evaluate Request XPath Assertion to extract the attribute vale using xpath. I have provided the xpath query for your XML below -
I have ignored namespaces in the above xpath expression. You can find more details on the assertion here
xpath assertion is one resolution, alternate resolution is Evaluate Regular Expression assertion.
Request body and results,
Hi All ,
I have same question , but how can I extract the value between <req:PAN> and </req:PAN> ?