Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to extract value of an Attribute of an element in SOAP Payload

MMJ
Bronze 2
Bronze 2

I have 2 questions. Both related to XML Payload.

Below is the Payload example:

<x:Envelope
xmlns:x="http://www.w3.org/2003/05/soap-envelope"
xmlns:tra="http://xml.blinkit.com/transaction"
xmlns:glo="http://xml.blinkit.com/globals">


<x:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>ABCDEFGHIJKLMNOPQRSTUVWXYZ</wsse:Username>
<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">123456789</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</x:Header>


<x:Body>
<tra:GetData>
<tra:ServiceRequest Timestamp="2019-08-09T01:08:12" BlinkitXMLVersion="2.0">
<tra:Member MemberID="12345" UserName="TD12345DXTRFV"></tra:Member>
<tra:Applicant>
<tra:Uin Type="SSN" Uin="666666666"/>
<tra:Name FirstName="AMAR" MiddleName = "KHAN" LastName="HU"/>
<tra:BirthDate>1989-10-28</tra:BirthDate>
<tra:Address Country="USA">
<glo:SimpleAddress Line1="24 XYZ ST" City="HOPKINTON" State="RI" PostalCode="56789"></glo:SimpleAddress>
</tra:Address>
</tra:Applicant>
</tra:ServiceRequest>
</tra:GetData>
</x:Body>

</x:Envelope>

1.> Can I extract the value of one of the attributes of an element in XML Payload via Extract Variable Policy in APIGEE Edge? I want to extract the value of MemberID from below payload. Please help me with the right Xpath. If I use below XPath [<XPath>//@MemberID</XPath>], it works. But if I add an additional or duplicate Line1 attribute in SimpleAddress, it fails. Why does it check the syntax or format of the XML? How do I avoid such checks at APIGEE layer so that I can pass the request to backend

2.> Is it the default nature of APIGEE to check the well formedness or validness of SOAP Payload in both Extract Variable Policy and XSLT Policy.

Similarly, in the XSLT policy I am trying to peel off the Security element under Header before sending request to backend. I am able to do so using XSLT policy if I am sending the above payload as mentioned. But if I add the below line instead as mentioned in the above payload it fails again.

<glo:SimpleAddress Line1="24 XYZ ST" Line1="25 XYZ ST" City="HOPKINTON" State="RI" PostalCode="56789"></glo:SimpleAddress>

How can I bypass such checks at APIGEE?

0 3 274
3 REPLIES 3

I am not quite clear on 2nd but for 1st you can just use below extract variable and get the value of MemberID. If you understand the usage you can do 2nd part as an assignment.

https://docs.apigee.com/api-platform/reference/policies/extract-variables-policy#xml

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-MemberID">
    <DisplayName>Extract MemberID</DisplayName>
    <Source>request</Source>
    <VariablePrefix>member</VariablePrefix>
    <XMLPayload>
        <Namespaces>
            <Namespace prefix="tra">http://xml.blinkit.com/transaction</Namespace>
        </Namespaces>
        <Variable name="id" type="string">
            <XPath>string(//tra:GetData/tra:ServiceRequest/tra:Member/@MemberID)</XPath>
        </Variable>
    </XMLPayload>
</ExtractVariables>

 

 

MMJ
Bronze 2
Bronze 2

Thanks a lot for your help. The first part is resolved.

Please suggest if its possible to handle duplicate attributes name in an element while using XSLT policy in APIGEE. A small sample shared below 

<ROOT>
  <A0>Hi</A0>
  <A1 A="hi" A="how" A="are" A="You?"></A1>
  <A2 A2="Bye"> </A2>
  <A3>In this tag have Hexa deimal value </A3>
</ROOT>

 

Good to know on first part..thankyou.

For second..

Duplicate attributes (on the same element) are not allowed in a well-formed XML document by definition.

May be ask different question with clear explanation or provide little more information..

General note:

What's your input request?

What's your expected result?

What you have done to address it and what is not working as expected?

It will help the readers..Kindly help me with appropriate details to help you..