03-25-2011 6:13 AM
Hi,
Im trying to upload some data from XML to abap. But Im getting an error while transforming xml data to internal table.
Here are the details.
XML:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Edited by XMLSpy® -->
<?xml-stylesheet type="text/xsl" href="ABAP1.xsl"?>
<conceptRevDecisionXml>
<projectInfo>
<projectId>P000755</projectId>
<stage>CON</stage>
<country>Ethiopia</country>
<region>AFRICA</region>
<teamleader>Priya Agarwal</teamleader>
<teamleaderfirstname>Priya</teamleaderfirstname>
<teamleaderlastname>Agarwal</teamleaderlastname>
<actionType>X</actionType>
</projectInfo>
</conceptRevDecisionXml>
XSLT: Transformation
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sapxsl="http://www.sap.com/sapxsl"
>
<xsl:strip-space elements="*"></xsl:strip-space>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<PROJID>
<xsl:apply-templates select="//conceptRevDecisionXml"></xsl:apply-templates>
</PROJID>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="conceptRevDecisionXml">
<xsl:for-each select="projectInfo">
<xsl:value-of select="projectId"></xsl:value-of>
<xsl:value-of select="stage"></xsl:value-of>
<xsl:value-of select="country "></xsl:value-of>
<xsl:value-of select="region"></xsl:value-of>
<xsl:value-of select="teamleader"></xsl:value-of>
<xsl:value-of select="teamleaderfirstname"></xsl:value-of>
<xsl:value-of select="teamleaderlastname"></xsl:value-of>
<xsl:value-of select="actionType"></xsl:value-of>
</xsl:for-each>
</xsl:template>
</xsl:transform>
Once I run the program...Im getting an error saying...ABAP XML Formatting error in XML node..
Im new to ABAP-XML parsing..Pls help me where Im going wrong..
Thanks in advance.
Regards,
Priya
03-25-2011 7:44 AM
Hi Priya,
you can try with the below,
1) Create a local ITAB with the structure of the XML,
TYPES: BEGIN OF t_data,
projectid TYPE char30,
stage TYPE char30,
country TYPE char30,
region TYPE char30,
teamleader TYPE char30,
teamleaderfirstname TYPE char30,
teamleaderlastname TYPE char30,
actiontype TYPE char30,
END OF t_data.
2) Create an XSLT prog in "STRANS" with the below code,
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<L_DATA>
<xsl:apply-templates select="//projectInfo"/>
</L_DATA>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="projectInfo">
<conceptRevDecisionXml>
<PROJECTID>
<xsl:value-of select="projectId"/>
</PROJECTID>
<STAGE>
<xsl:value-of select="stage"/>
</STAGE>
<COUNTRY>
<xsl:value-of select="country"/>
</COUNTRY>
<REGION>
<xsl:value-of select="region"/>
</REGION>
<TEAMLEADER>
<xsl:value-of select="teamleader"/>
</TEAMLEADER>
<TEAMLEADERFIRSTNAME>
<xsl:value-of select="teamleaderfirstname"/>
</TEAMLEADERFIRSTNAME>
<TEAMLEADERLASTNAME>
<xsl:value-of select="teamleaderlastname"/>
</TEAMLEADERLASTNAME>
<ACTIONTYPE>
<xsl:value-of select="actionType"/>
</ACTIONTYPE>
</conceptRevDecisionXml>
</xsl:template>
</xsl:transform>
3) Call the transformation as shown below,
CALL TRANSFORMATION zxslt_project ---> "Name of the XSLT prog created above
SOURCE XML l_xml_str ---> Source XML string
RESULT l_data = l_data. ---> ITAB as in step 1 above
Regards,
Chen