how to extract particular xml element from payload

How tp extract the value of ID from the below XML. I just want the value "24070812"<SubmitOrderRequest>

<Order>

<OrderExtendedDataDictionary>

<Value Key="IPAddress">172.30.200.164</Value>

<Value Key="ID">24070812</Value>

</OrderExtendedDataDictionary

</Order>

</SubmitOrderRequest>

Solved Solved
1 2 1,728
1 ACCEPTED SOLUTION

faijahmad
Participant V
Use Extract Variable policy. See below code 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="extractXMLPaayload">
    <DisplayName>extractXMLPaayload</DisplayName>
    <Source clearPayload="false">request</Source>
    <VariablePrefix>order</VariablePrefix>
    <XMLPayload stopPayloadProcessing="false">
        <Namespaces/>
        <Variable name="key" type="integar">
            <XPath>//SubmitOrderRequest/Order/OrderExtendedDataDictionary/Value[@Key='ID']/text()</XPath>
        </Variable>
    </XMLPayload>
</ExtractVariables>

You can check this extracted value by printing in JS policy

var key = context.getVariable('order.key');
print(key);

View solution in original post

2 REPLIES 2

faijahmad
Participant V
Use Extract Variable policy. See below code 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="extractXMLPaayload">
    <DisplayName>extractXMLPaayload</DisplayName>
    <Source clearPayload="false">request</Source>
    <VariablePrefix>order</VariablePrefix>
    <XMLPayload stopPayloadProcessing="false">
        <Namespaces/>
        <Variable name="key" type="integar">
            <XPath>//SubmitOrderRequest/Order/OrderExtendedDataDictionary/Value[@Key='ID']/text()</XPath>
        </Variable>
    </XMLPayload>
</ExtractVariables>

You can check this extracted value by printing in JS policy

var key = context.getVariable('order.key');
print(key);

There's lots of online XPath testers such as https://codebeautify.org/Xpath-Tester