SAP PI Interview Questions and SAP PI Tutorials
SAP PI Interview Questions and SAP PI Tutorials
Consuming Webservices with <ANY> tag in WSDL using XSLT
Have you seen the blog Consuming Webservices with <ANY> tag in WSDL using ABAPÂ where posted the ABAP solution of empty structures in .Net WEB services? This blog shows another approach – XSLT mapping program.
The problem is in that fact that WSDL file generated with .Net WEB service (MS Project server, MS SharePoint server, etc.) contains link
<s:any namespace=" ... " xmlns:s="http://www.w3.org/2001/XMLSchema" /> |
Â
in element
<s:sequence xmlns:s="http://www.w3.org/2001/XMLSchema"> ... </s:sequence> |
Â
of message type definition. Here target is in “namespace” attribute. Using this WSDL in SAP XI/PI, you will get a message without fields in message mapping. At runtime there will be only one element with whole message into it as its value.
You can modify WSDL copying this structure in “sequence” element of cause but to my mind it is not right way.
Using ABAP is not suitable in some cases, especially when you haven’t got OSS key.
I have solved this problem using XSLT. Â
So, I got a response from MS Project’s WEB service like this:
 <?xml version="1.0" encoding="UTF-8"?>  <ReadProjectListResponse xmlns="http://schemas.microsoft.com/office/project/server/webservices/Project/"> <ReadProjectListResult>  <xs:schema ... > ... </xs:schema>  <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> <ProjectDataSet xmlns="http://schemas.microsoft.com/office/project/server/webservices/ProjectDataSet/"> <Project diffgr:id="Project1" msdata:rowOrder="0" diffgr:hasChanges="inserted"> <PROJ_UID>674457db-7ff1-4e24-81b3-b41d5594f27f</PROJ_UID>   <PROJ_NAME>Project1</PROJ_NAME> </Project> <Project diffgr:id="Project2" msdata:rowOrder="1" diffgr:hasChanges="inserted">   <PROJ_UID>3dc33ef5-c796-4b01-8707-3b1f225f741c</PROJ_UID>   <PROJ_NAME>Project2</PROJ_NAME> </Project> </ProjectDataSet> </diffgr:diffgram> </ReadProjectListResult> </ReadProjectListResponse> |
         Â
In this message I want to get a list of Projects UIDs (<PROJ_UID>).
First step was “cut” redundant namespaces using XMLAnonymizerBean module
Next, I wrote script like this:
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="ProjectDataSet"> Â <MT_Project_List> Â Â <xsl:apply-templates /> Â </MT_Project_List> </xsl:template> <xsl:template match="Project"> Â Â <row> Â Â Â Â Â <xsl:apply-templates select="PROJ_UID" /> Â Â </row> </xsl:template> <xsl:template match="PROJ_UID"> Â Â <projectUID> Â Â Â Â Â <xsl:apply-templates /> Â Â </projectUID> </xsl:template> </xsl:stylesheet> |
        Â
In this script templates
<xsl:template match="XXXX"> Â <YYYY> Â Â <xsl:apply-templates /> Â </YYYY> </xsl:template> |
Â
search <XXXX> elements in input XML, call next template and put its result in <YYYY> element of output file. If next template is not exists, it returns value of current element.
So, my response from MS Project transforms to:
 <?xml version="1.0" encoding="UTF-8"?> <MT_Project_List> <row> <projectUID>674457db-7ff1-4e24-81b3-b41d5594f27f</projectUID> </row> <row> <projectUID>3dc33ef5-c796-4b01-8707-3b1f225f741c</projectUID> </row> </MT_Project_List> |
Â
It works!
And the last step – is to archive an XSLT file, import it as Imported Archive and choose it in Interface Mapping as mapping program (type=XSL).
P.S.
SAP PI Interview Questions and SAP PI Tutorials
SAP PI Interview Questions and SAP PI Tutorials
If you need to get 2 or more fields, your XSLT should be a changed. For example, XSLT for Projects IDs and Names:
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="ProjectDataSet"> Â <MT_Project_List> Â Â Â <xsl:apply-templates /> </MT_Project_List> </xsl:template> <xsl:template match="Project"> Â Â <row> Â Â Â Â Â <xsl:apply-templates select="PROJ_UID" /> Â Â Â Â Â <xsl:apply-templates select="PROJ_NAME" /> Â Â </row> </xsl:template> <xsl:template match="PROJ_UID"> Â Â <projectUID> Â Â Â Â Â <xsl:apply-templates /> Â Â </projectUID> </xsl:template> <xsl:template match="PROJ_NAME"> Â Â <projectNAME> Â Â Â Â Â <xsl:apply-templates /> Â Â </projectNAME> </xsl:template> </xsl:stylesheet> |
Â
Output:
<?xml version="1.0" encoding="UTF-8"?> <MT_Project_List> <row> <projectUID>674457db-7ff1-4e24-81b3-b41d5594f27f</projectUID> <projectNAME>Project1</projectNAME> </row> <row> <projectUID>3dc33ef5-c796-4b01-8707-3b1f225f741c</projectUID> <projectNAME>Project2</projectNAME> </row> </MT_Project_List> |
SAP PI Interview Questions and SAP PI Tutorials
SAP PI Interview Questions and SAP PI Tutorials