0

I have request message, in which the required fields are in CDATA, i need to retreive those fields and create a new request and send it to Backend in Data power.

Request message:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/456/" xmlns:soapenv1="http://example.com/ns1/CIP_Request.xsd">
    <soapenv:Header/>
    <soapenv:Body>
        <ns1:InqAccts>
            <ns1:reqxml>
                <![CDATA[<?xml version="1.0" encoding="utf-8"?><CIP_Request schemaVersion="3.0" xmlns="http://example.com/456/CIP_Request.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><UUID>97538E5A-ED0D-6A2F-97D86FE4DEEB6698</UUID><ClientCode>AND</ClientCode><InqDetails><AID>138716123</AID><CID>12345</CID><Desc>Sample</Desc></InqDetails></CIP_Request>]]></ns1:reqxml>
        </ns1:InqAccts>
    </soapenv:Body>
</soapenv:Envelope>

XSLT :

<xsl:stylesheet version="1.0" extension-element-prefixes="dp" exclude-result-prefixes="dp xalan" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:dp="http://www.datapower.com/extensions" 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ns1="http://example.com/456/" 
 xmlns:ns="http://output.com/123/" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

    <xsl:variable name="result" select="//soapenv:Envelope/soapenv:Body/nao:InqAccts/nao:reqxml"/>

    <xsl:variable name="xmlResult">
        <dp:serialize omit-xml-decl="yes" select="//nao:reqxml" disable-output-escaping="yes" />
    </xsl:variable>

    <xsl:variable name="AID" select="$xmlResult//InqDetails/AID"/>
    <xsl:variable name="CID" select="$xmlResult//InqDetails/CID"/>
    <xsl:variable name="DESC" select="$xmlResult//InqDetails/Desc"/>

    <xsl:template match="/">
        <soapenv:Envelope>
            <soapenv:Header/>
            <soapenv:Body>
                <ns:DetailsGetRq>
                    <DetailAID>
                        <xsl:value-of select="$AID"/> 
                    </DetailAID>
                    <DetailCID>
                        <xsl:value-of select="$CID"/>
                    </DetailCID>
                    <desc>
                        <xsl:value-of select="$DESC"/>
                    </desc>
                </ns:DetailsGetRq>
            </soapenv:Body>
        </soapenv:Envelope>
    </xsl:template>

</xsl:stylesheet>

The Converted request which i am looking for is this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ns1="http://example.com/456/" 
 xmlns:ns="http://output.com/123/" >
    <soapenv:Header />
    <soapenv:Body>
        <ns:DetailsGetRq>
            <DetailAID>138716123</DetailAID>
            <DetailCID>12345</DetailCID>
            <desc>Sample</desc>
        </ns:DetailsGetRq>
    </soapenv:Body>
</soapenv:Envelope>

I need help in parsing CDATA value into XML and retrieve the field values from the same.

Please do let me know which is the way to proceed for the same.

Thank you!!

Vinay
  • 1
  • 3
  • Your input XML is broken. The CDATA is not supposed to be in there at all. Instead of working around the issue, I strongly recommend fixing the input. – Tomalak Jul 08 '14 at 17:07
  • I can't edit the input message, reqxml is defined as string in the XSD and WSDL provided by the application team which we are consuming it. I have updated the input message let me know is there any way we can do it? – Vinay Jul 09 '14 at 08:42
  • So you have no way of going to your own application team and telling them that they should fix that mistake? That's sad. Then you must do it the way suggested here: http://stackoverflow.com/questions/2067116/convert-an-xml-element-whose-content-is-inside-cdata – Tomalak Jul 09 '14 at 09:04

0 Answers0