Layer7 API Management

  • 1.  How to convert xml request body into string removing xml declaration

    Posted Dec 22, 2017 02:21 PM

    How to remove XML declaration and white spaces in request XML and convert the XML into string

     

    Gateway 9.2

    I am able to remove white spaces and XML declaration using regular expression assertion but I am not able to get my desired response

     

    Input xml 

    <?xml version="1.0" encoding="UTF-8"?>
    <Request>
    <sourceappcode>RCAS</sourceappcode>
    <RqUID></RqUID>
    <message_type_cd>KB100</message_type_cd>
    <TransactionId>ABC12345</TransactionId>
    <reportType>xml</reportType>
    <txnId>qwert</txnId>
    <vendorId>123456</vendorId>
    </Request>

     

    Output xml

    <Request><sourceappcode>RCAS</sourceappcode><RqUID></RqUID>message_type_cd>KB100</message_type_cd><TransactionId>ABC12345</TransactionId>reportType>xml</reportType><txnId>qwert</txnId><vendorId>123456</vendorId></Request>

     

    Need to convert the request XML into string by removing XML declaration 



  • 2.  Re: How to convert xml request body into string removing xml declaration

    Broadcom Employee
    Posted Dec 22, 2017 02:34 PM

    Hi Irfan,

     

    To remove the XML declaration you can use XSLT, something along these lines:

     

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
    <xsl:template match="@*|*|processing-instruction()|comment()">
    <xsl:copy>
    <xsl:apply-templates select="*|@*|text()|processing-instruction()|comment()"/>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>

     

     

    Trim white spaces in Split Variable Assertion 

     

    Regards,

    Joe



  • 3.  Re: How to convert xml request body into string removing xml declaration

    Posted Dec 22, 2017 02:40 PM

    Thank you for the xsl,But i also need to remove the white spaces and transform the xml in one line string as same as i shown in my output which i need.



  • 4.  Re: How to convert xml request body into string removing xml declaration

    Broadcom Employee
    Posted Dec 22, 2017 03:13 PM

    Whitespace can be removed with RegEx.

     

    Trim white spaces in Split Variable Assertion 

     

     

     

     

     



  • 5.  Re: How to convert xml request body into string removing xml declaration
    Best Answer

    Broadcom Employee
    Posted Dec 22, 2017 03:31 PM

    Optionally, RegEx can also be used to remove the declaration. See the attached sample.

     

    <\?xml version=\"1.0\" encoding=\"UTF-8\"\?>

     

     

    xml_declaration.xml - remove declaration and whitespace using only RegEx

    xml_declaration_xslt.xml - remove declaration using XSLT and whitespace using RegEx.

    Attachment(s)

    zip
    xml_declaration.xml.zip   649 B 1 version


  • 6.  Re: How to convert xml request body into string removing xml declaration

    Posted Dec 26, 2017 01:34 AM

    Thank you for your help.