How to modify a value in XML payload

I am sending a request to a SOAP service
Below is the payload:
<s:Envelope xmlns:s=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:u=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd”>
<s:Header>
00000000-0000-0000-0000-000000000000
<o:Security
s:mustUnderstand=“1”
xmlns:o=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd”>
<u:Timestamp u:Id=“_0”><u:Created>2023-06-02T10:08:12.039Z</u:Created><u:Expires>2023-06-02T10:13:12.039Z</u:Expires></u:Timestamp><o:Username>someusername</o:Username><o:Password Type=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText”>*****</o:Password>
</o:Security>
</s:Header>
<s:Body>
</s:Body></s:Envelope>

I want to edit the payload and set s:mustUnderstand = “0”

Please let me know if there is any way

Hey there!

What you describe - modifying an XML payload - is a somewhat common desire, in Apigee. I’ve answered similar questions in the past. I’ll direct you to one of my answers, which still applies here.

See here.

Good luck!

1 Like

Yes, you can transform XML in Apigee easily with the XSLTransform Policy. You will need to write your own XSLT transformation though to update the attribute s:mustUnderstand = “0”. The below transform could help as a starting point, please review and adjust accordingly.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

  <xsl:template match="@*|node()">
    <xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
  </xsl:template>

  <xsl:template match="o:Security/@s:mustUnderstand" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <xsl:attribute name="{name()}">0</xsl:attribute>
  </xsl:template>

</xsl:stylesheet>
2 Likes

Thank you @dchiesa1 . After couple of modifications I was able to get the solution.

Thank you @pablosan . I create the policy using this and it worked.

1 Like