Skip to Content
avatar image
Former Member

Rest Adapter - Need To Strip Hierarchy level XML Root nodes

Scenario :- REST---->PI----->SAP (Synchronous)

I need to strip Root node (MT_Test) and sub node (root), i am able to strip root node but unable to strip sub node

Expected JSON Response Back

[ { "Name": "TEST1", "No": "TEST1", "CompanyDetails": [ { "id": "TEST1" "Name": "TEST1" } ] }, { "Name": "TEST2", "No": "TEST2", "CompanyDetails": [ { "id": "TEST2" "Name": "TEST2" } ] } ]

Received Response

[{"root": [ { "Name": "TEST1", "No": "TEST1", "CompanyDetails": [ { "id": "TEST1", "name": "TEST1", }] }, { "Name": "TEST2", "No": "TEST2", "CompanyDetails": [ { "id": "TEST2", "name": "TEST2", }] } ]}]

ESR - Message Type

<?xml version="1.0" encoding="UTF-8"?> <MT_Test> <root> <Name>TEST1</Name> <No>TEST1</No> <CompanyDetails> <id>TEST1</id> <name>TEST1</name> </CompanyDetails> </root> <root> <Name>TEST2</Name> <No>TEST2</No> <CompanyDetails> <id>TEST2</id> <name>TEST2</name> </CompanyDetails> </root> </MT_Test>

Issue :- I am able to strip of MT_Test using option "Strip Outer Element" in sender channel but unable to strip node (root), i tired to use replace strip custom adapter module but get error unable to parse, tried xslt and java maps still no luck

Any suggestion are appreciated

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Feb 28 at 07:30 AM

    Hi Gaurav ,

    use below XSLT code , which should work .

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://use your namespace">
        <xsl:output method="text"/>
    
    
        <xsl:template match="/ns0:MT_Test">{
            <xsl:apply-templates select="*"/> }
        </xsl:template>
        
        <!-- Object or Element Property-->
        <xsl:template match="*">
    	
            "<xsl:value-of select="name()"/>" : <xsl:call-template name="Properties"/>
    		
    	
        </xsl:template>
    
    
        <!-- Array Element -->
        <xsl:template match="*" mode="ArrayElement">
            <xsl:call-template name="Properties"/>
        </xsl:template>
    
    
        <!-- Object Properties -->
        <xsl:template name="Properties">
            <xsl:variable name="childName" select="name(*[1])"/>
            <xsl:choose>
                <xsl:when test="not(*|@*)">"<xsl:value-of select="."/>"</xsl:when>
                <xsl:when test="count(*[name()=$childName]) > 1">{ "<xsl:value-of select="$childName"/>" :[<xsl:apply-templates select="*" mode="ArrayElement"/>] }</xsl:when>
                <xsl:otherwise>{
                    <xsl:apply-templates select="@*"/>
                    <xsl:apply-templates select="*"/>
        }</xsl:otherwise>
            </xsl:choose>
            <xsl:if test="following-sibling::*">,</xsl:if>
        </xsl:template>
    
    
        <!-- Attribute Property -->
        <xsl:template match="@*">"<xsl:value-of select="name()"/>" : "<xsl:value-of select="."/>",
        </xsl:template>
    </xsl:stylesheet>
    
    Add comment
    10|10000 characters needed characters exceeded

  • Feb 02 at 09:44 AM

    Try to set the REST module parameter "setIgnoredElements" using which you can remove the required XML elements while converting to JSON. Refer SAP note # 2465948.

    ---Priyanka

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 02 at 03:19 PM

    I was aware of this but we are on PI 7.4 version and this parameter is for new PI versions and does this works for sender adapter as notes says for receiver adapter

    Do we have any other means as a work around like java map or xslt ?

    Thank you

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 09 at 01:47 PM

    hi, have this issue sloved yet?

    I am in the same condition. Could you plese share me the solution?

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded