XML to ABAP Using XSLT
Hello friends,
I am trying a ABAP program (posted on SDN) to convert XML into ABAP (internal table) and not having any luck. Either it is my table/structure declaration or XSLT. Could any of you experts give me a hand with it please?
Thanks in advance..but points on help!
Here is my XML:
And my ABAP program:
REPORT ZTESTXMLREAD.
TYPE-POOLS: abap, ixml.
class cl_ixml definition load.
TYPES: BEGIN OF t_dc40,
docnum(17) TYPE C,
status(2) TYPE C,
END OF t_dc40.
TYPES: BEGIN OF t_emkt,
spras(2) TYPE C,
maktx(35) TYPE C,
END OF t_emkt.
TYPES: BEGIN OF t_emrm,
matnr(12) TYPE C,
ersda(8) TYPE C,
ernam(25) TYPE C,
emktx TYPE t_emkt,
END OF t_emrm.
TYPES: BEGIN OF t_mm,
dc40 TYPE t_dc40,
emrm TYPE t_emrm,
END OF t_mm.
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_istream TYPE REF TO if_ixml_istream.
DATA: l_filename TYPE string.
DATA: it_airplus TYPE STANDARD TABLE OF t_mm,
wa_airplus TYPE t_mm.
*Errorvariables
DATA: xslt_err TYPE REF TO cx_xslt_exception,
err_string TYPE string.
PARAMETERS: pa_file TYPE char1024 DEFAULT 'c:Test.XML'.
START-OF-SELECTION.
Creating the main iXML factory
l_ixml = cl_ixml=>create( ).
Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
Creating input stream
l_istream = l_streamfactory->create_istream_uri( 'file://c:Test.xml' ).
here we use the CALL TRANSFORMATION method which calls
TRY.
CALL TRANSFORMATION ZTestXSLT
SOURCE xml l_istream
RESULT xml_output = it_airplus
catch any error, very helpful if the XSLT isn't correct
CATCH cx_xslt_exception INTO xslt_err.
err_string = xslt_err->get_text( ).
WRITE: / 'Transformation error: ', err_string.
EXIT.
ENDTRY.
setting a breakpoint to watch the workarea
by the internal table "it_airplus"
break-point.
LOOP AT it_airplus INTO wa_airplus.
ENDLOOP.
Thank you Durairaj, as a matter of fact my program is based on your post (one that you pointed me to). For whatever reason I'm not having luck figuring it out (may be just a bit of work pressure) could you please hlep me a bit more by pointing me to where in my program code/xslt I'm going wrong? I somehow feel that it could be my table structure or xslt.
I would really appreciate it!
Thanks again,
erfan.
Similar Messages
-
How to find XSD file? XML to ABAP using XSLT convertor
Hi Gurus,
I am trying to convert an XML file to ABAP internal tables using an XSLT transformation. I used the code posted by Durairaj (XSLT program Y_XML_2_ITAB_SIMPLE as mentioned in the link: [Y_XML_2_ITAB_SIMPLE|Parse data to Internal Table;) and the code worked fine.
My XML file structure is different, and when I try to modify the code for my purposes I got stuck. While changing the XML file strings in the report, I am unable to replace the tag xsi:noNamespaceSchemaLocation="invoice_btm.xsd" correctly. I am also not sure what this file "invoice_btm.xsd" does and where it is stored. When I remove the tag, I get other errors and cannot proceed ahead.
Can you please advice as to how I should proceed? Also, where can I see the XSD file? can I add a XSD file for my own XML? Or, is there a way to eliminate the need for an XSD file altogether?
Thanks in advance.
Regards,
Shailesh.Hi guys,
Any help would be most helpful. Thanks again,
Hi guys,
Any ideas on this issue? Thanks again for your help.
Hi Naimesh,
Thanks for the quick reply. I am getting the error "The element abap was expected for the XML-ABAP transformation". I have replaced the following:
1) "INVOICES_BTM" with the string "ACCOUNT_INFO"
2) "INVOICE_BTM" with the string "ROOTNODE"
My XSLT:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:template match="ACCOUNT_INFO">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<OUTPUT>
<xsl:for-each select="ROOTNODE">
<items>
<INV_DATE>
<xsl:value-of select="INVOICE_HEAD/INVOICE_DATE"/>
</INV_DATE>
<INV_NO>
<xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/NUMBER"/>
</INV_NO>
<INV_EXT>
<xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/EXTENSION"/>
</INV_EXT>
<INV_SEQ>
<xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/SEQUENCE"/>
</INV_SEQ>
</items>
</xsl:for-each>
</OUTPUT>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>
My XML program:
TYPES: BEGIN OF stru,
inv_date(10),
inv_no(50),
inv_ext(10),
inv_seq(10),
END OF stru.
DATA: outtab TYPE STANDARD TABLE OF stru .
DATA: xslt_error TYPE REF TO cx_xslt_exception,
xslt_message TYPE string .
DATA: xml_string TYPE string .
CLEAR xml_string .
CONCATENATE
'<?xml version="1.0" encoding="ISO-8859-1"?>'
'<ACCOUNT_INFO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ROOTNODE.xsd">'
'<ROOTNODE>'
'<INVOICE_HEAD LANGUAGE="DE" DIRECT_DEBIT_QUALIFIER="NO">'
'<INVOICE_DATE>20040112</INVOICE_DATE>'
'<INVOICE_NUMBER>'
'<NUMBER>0306299999</NUMBER>'
'<EXTENSION>1</EXTENSION>'
'<SEQUENCE>01</SEQUENCE>'
'</INVOICE_NUMBER>'
'</INVOICE_HEAD>'
'</ROOTNODE>'
'<ROOTNODE>'
'<INVOICE_HEAD LANGUAGE="DE" DIRECT_DEBIT_QUALIFIER="NO">'
'<INVOICE_DATE>20040113</INVOICE_DATE>'
'<INVOICE_NUMBER>'
'<NUMBER>0306299888</NUMBER>'
'<EXTENSION>2</EXTENSION>'
'<SEQUENCE>02</SEQUENCE>'
'</INVOICE_NUMBER>'
'</INVOICE_HEAD>'
'</ROOTNODE>'
'</ACCOUNT_INFO>'
INTO xml_string .
TRY .
CALL TRANSFORMATION ('ZH2_XML_TRANS_I1')
SOURCE XML xml_string
RESULT output = outtab.
CATCH cx_xslt_exception INTO xslt_error.
xslt_message = xslt_error->get_text( ).
ENDTRY.
break-point.
Edited by: Shailesh S Kamath on Jan 16, 2012 2:17 PM
Edited by: Shailesh S Kamath on Jan 30, 2012 2:47 PM -
Generating CDATA containing XML-like text using XSLT Mapper in OFM 11g
Hi,
One of our partners requires XML to be sent as XML string inside a CDATA section. The use of "real" XML is not an option at the moment. We try to generate something like the following using XSLT/XSLT Mapper in SOA Suite 11g:
<element>
<![CDATA[
<supplierElement1>
<supplierElement2>
etcetera
<supplierElement2>
</supplierElement1>
]]>
</element>
We've tried the following two approaches, so far unsuccessful:
<xsl:template match="/">
<inp1:singleString>
<inp1:input>
<xsl:text disable-output-escaping="yes"><![CDATA[test]]></xsl:text>
</inp1:input
</inp1:singleString>
</xsl:template>
resulting in:
<inp1:singleString xmlns:inp1="http://xmlns.oracle.com/singleString">
<inp1:input><![CDATA[test]]></inp1:input>
</inp1:singleString>
and:
<xsl:output method="xml" indent="yes" cdata-section-elements="input"/>
<xsl:template match="/">
<inp1:singleString>
<input>test</input>
</inp1:singleString>
</xsl:template>
resulting in:
<inp1:singleString xmlns:inp1="http://xmlns.oracle.com/singleString" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<input>test</input>
</inp1:singleString>
Does anyone know how to generate the CDATA section declaratively (within XSLT/XSLT Mapper), without resorting to custom code and parsing as we have to do now?
Thanks!
RonaldThe exact error message I'm getting is :
ABAP XML formatting error in XML node of type "element", name: "abap" -
Problem in transforming XML to string using XSLT
Hi there,
I have a R/3 -> XI -> WebService scenario where the message from XI to webservice needs to be sent in document/wrapped mode (the message xml must be embedded in a string element) and this message needs to be digitally signed.
We are using another webservice to sign the messages, also with the message being sent in a string. To transform the XML's into string and vice-versa, we are using XSLT (/people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping).
The problem is that both the signer and the final webservice understand the special characters (like '<', '>', '&', '"' etc) in one way but the XSLT generates them in another way. For example, the character '<', in both webservices, is returned as "<" but the XSL Transformation results in "<".
The problem now is that our messages are always being rejected because the signature is not being recognized as true, though we are almost 100% sure that it's being done correctly. The only possibility to the error that we found is this character mapping being done differently.
So, it's like this:
XI sends string to signer as "<"
XI receives string from signer as "<"
XI processes the message
XI sends string to webservice as "<"
XI receives string from webservice (containing error message) as "<"
Is there a way of making the XSLT to return "<" instead of "<"?
Thanks in advace,
Henrique.For Java Mapping, you can refer this-
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
In Java Mapping, in the startdocument event , you need to check for the specialchars, and just repalce the value required.
But, what i am thinking is , just try with Java functions inside the XSLT mapping instead of going for Java Mapping. You can call java functions from the XSLT. So before the document starts pasring, you need to replace the special characters. I did not try in XSLT like this.
For this , you can think with this e.g
/people/pooja.pandey/blog/2005/06/27/xslt-mapping-with-java-enhancement-for-beginners
Regards,
Moorthy -
How to ignore prefix from XML while converting XML to csv using XSLT
Hi All,
I am trying to convert XML to csv file.
the XML i have is like....
<?xml version="1.0"?>
<bulkCmConfigDataFile xmlns:es="SpecificAttributes.3.0.xsd" xmlns:un="utranNrm.xsd" xmlns:xn="genericNrm.xsd" xmlns:gn="geranNrm.xsd" xmlns="configData.xsd">
<configData dnPrefix="Undefined">
<xn:SubNetwork id="AU_R">
<xn:SubNetwork id="H5RG_0501">
<xn:MeContext id="Firle_5070020">
<xn:ManagedElement id="1">
<un:RncFunction id="1">
<un:UtranCell id="50390303">
<un:attributes>
<un:userLabel>UtranCell 50390303</un:userLabel>
<un:cId>52383</un:cId>
<un:localCellId>50390303</un:localCellId>
<un:uarfcnUl>9613</un:uarfcnUl>
<un:uarfcnDl>10563</un:uarfcnDl>
<un:primaryScramblingCode>502</un:primaryScramblingCode>
<un:primaryCpichPower>287</un:primaryCpichPower>
<un:maximumTransmissionPower>403</un:maximumTransmissionPower>
<un:primarySchPower>-18</un:primarySchPower>
<un:secondarySchPower>-20</un:secondarySchPower>
<un:bchPower>-20</un:bchPower>
<un:lac>50301</un:lac>
<un:rac>1</un:rac>
<un:sac>52383</un:sac>
<un:utranCellIubLink>SubNetwork=AU_R,SubNetwork=H5RG_0501,MeContext=H5RG_0501,ManagedElement=1,RncFunction=1,IubLink=5039030</un:utranCellIubLink>
</un:attributes>
</un:UtranCell>
</un:RncFunction>
</xn:ManagedElement>
</xn:MeContext>
</xn:SubNetwork>
</xn:SubNetwork>
</configData>
</bulkCmConfigDataFile>now when i am using XSLT functionality to convert this XML into a csv i want ignore all the prefix from this xml like "un" , "xn" etc....
can anybody has idea how i can ignore all this value using XSLTI just dont understand why factory.setIgnoringElementContentWhitespace(true) did not work.That only does something if the XML has a DTD that enables it to know what whitespace can be ignored and what is significant. The API documentation for the method refers you to this document:
http://www.w3.org/TR/REC-xml#sec-white-space -
SAP 4.7 XML data exchange using XSLT
Hello All,
Hopefully the right place to post such article but here goes any way.
My project involves producing XML files and then reading them back into to SAP internal tables. I am ok with writing SAP data to external XML file but reading it back in is causing a lot of head scratching.
I am able to double click the XML file and it launches Ok in Internet Explorer.
I am also able to debug the xslt file from within SE80 and the correct output is displayed.
However, where I am trying to read the contents of the xml file via the Call Transformation procedure call my output table is not getting populated but instead I am recieving an error message saying the following is not correct:
xmlns:sapxsl="http://www.sap.com/sapxsl
but the above line is placed automaticlly in the XSLT when you create a new one from within SE80.
I am new to SAP ABAP development so not sure what's exactly wrong.
Any help on this issue will be greatfully appreciated. Thanks in Advance,
Wasif
REPORT z_hp_xml_test .
TYPE-POOLS: ixml.
TABLES: tstc, tstct.
TYPES: BEGIN OF ty_transactions,
tcode LIKE tstc-tcode,
ttext LIKE tstct-ttext,
sprsl LIKE tstct-sprsl,
END OF ty_transactions.
DATA: itab_transactions TYPE STANDARD TABLE OF ty_transactions.
TYPES: BEGIN OF t_xml_line,
data(256) TYPE x,
END OF t_xml_line.
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_parser TYPE REF TO if_ixml_parser,
l_istream TYPE REF TO if_ixml_istream,
l_document TYPE REF TO if_ixml_document,
l_node TYPE REF TO if_ixml_node,
l_xmldata TYPE string.
DATA: l_elem TYPE REF TO if_ixml_element,
l_root_node TYPE REF TO if_ixml_node,
l_next_node TYPE REF TO if_ixml_node,
l_name TYPE string,
l_iterator TYPE REF TO if_ixml_node_iterator.
DATA: l_xml_table TYPE TABLE OF t_xml_line,
l_xml_line TYPE t_xml_line,
l_xml_table_size TYPE i.
DATA: l_filename TYPE string.
PARAMETERS: pa_file TYPE char1024 DEFAULT 'C: emp ransactions.xml'.
Validation of XML file: Only DTD included in xml document is supported
PARAMETERS: pa_val TYPE char1 AS CHECKBOX.
START-OF-SELECTION.
Creating the main iXML factory
l_ixml = cl_ixml=>create( ).
Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
PERFORM get_xml_table CHANGING l_xml_table_size l_xml_table.
wrap the table containing the file into a stream
l_istream = l_streamfactory->create_istream_itable( table =
l_xml_table
size =
l_xml_table_size ).
Creating a document
l_document = l_ixml->create_document( ).
Create a Parser
l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
istream = l_istream
document = l_document ).
Validate a document
IF pa_val EQ 'X'.
l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
ENDIF.
Parse the stream
If any errors then disply else convert XML to table
IF l_parser->parse( ) NE 0.
IF l_parser->num_errors( ) NE 0.
DATA: parseerror TYPE REF TO if_ixml_parse_error,
str TYPE string,
i TYPE i,
count TYPE i,
index TYPE i.
count = l_parser->num_errors( ).
WRITE: count, ' parse errors have occured:'.
index = 0.
WHILE index < count.
parseerror = l_parser->get_error( index = index ).
i = parseerror->get_line( ).
WRITE: 'line: ', i.
i = parseerror->get_column( ).
WRITE: 'column: ', i.
str = parseerror->get_reason( ).
WRITE: str.
index = index + 1.
ENDWHILE.
ENDIF.
ELSE.
TRY .
CALL TRANSFORMATION (`Z_HP_TEST_XSLT`)
SOURCE XML l_xml_table
RESULT outtab = itab_transactions.
DATA: xslt_err TYPE REF TO cx_xslt_exception .
CATCH cx_xslt_exception INTO xslt_err.
DATA: s TYPE string.
s = xslt_err->get_text( ).
WRITE: ': ', s.
STOP.
ENDTRY .
Process the document
IF l_parser->is_dom_generating( ) EQ 'X'.
PERFORM process_dom USING l_document.
ENDIF.
ENDIF.
*& Form get_xml_table
FORM get_xml_table CHANGING l_xml_table_size TYPE i
l_xml_table TYPE STANDARD TABLE.
Local variable declaration
DATA: l_len TYPE i,
l_len2 TYPE i,
l_tab TYPE tsfixml,
l_content TYPE string,
l_str1 TYPE string,
c_conv TYPE REF TO cl_abap_conv_in_ce,
l_itab TYPE TABLE OF string.
l_filename = pa_file.
upload a file from the client's workstation
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = l_filename
filetype = 'BIN'
IMPORTING
filelength = l_xml_table_size
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Writing the XML document to the screen
CLEAR l_str1.
LOOP AT l_xml_table INTO l_xml_line.
c_conv = cl_abap_conv_in_ce=>create( input = l_xml_line-data
replacement = space ).
c_conv->read( IMPORTING data = l_content len = l_len ).
CONCATENATE l_str1 l_content INTO l_str1.
ENDLOOP.
l_str1 = l_str1+0(l_xml_table_size).
SPLIT l_str1 AT cl_abap_char_utilities=>cr_lf INTO TABLE l_itab.
WRITE: /.
WRITE: /' XML File'.
WRITE: /.
LOOP AT l_itab INTO l_str1.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab
IN
l_str1 WITH space.
WRITE: / l_str1.
ENDLOOP.
WRITE: /.
ENDFORM. "get_xml_table
*& Form process_dom
FORM process_dom USING document TYPE REF TO if_ixml_document.
DATA: node TYPE REF TO if_ixml_node,
iterator TYPE REF TO if_ixml_node_iterator,
nodemap TYPE REF TO if_ixml_named_node_map,
attr TYPE REF TO if_ixml_node,
name TYPE string,
prefix TYPE string,
value TYPE string,
indent TYPE i,
count TYPE i,
index TYPE i.
node ?= document.
CHECK NOT node IS INITIAL.
ULINE.
WRITE: /.
WRITE: /' DOM-TREE'.
WRITE: /.
IF node IS INITIAL. EXIT. ENDIF.
create a node iterator
iterator = node->create_iterator( ).
get current node
node = iterator->get_next( ).
loop over all nodes
WHILE NOT node IS INITIAL.
indent = node->get_height( ) * 2.
indent = indent + 20.
CASE node->get_type( ).
WHEN if_ixml_node=>co_node_element.
element node
name = node->get_name( ).
nodemap = node->get_attributes( ).
WRITE: / 'ELEMENT :'.
WRITE: AT indent name COLOR COL_POSITIVE INVERSE.
IF NOT nodemap IS INITIAL.
attributes
count = nodemap->get_length( ).
DO count TIMES.
index = sy-index - 1.
attr = nodemap->get_item( index ).
name = attr->get_name( ).
prefix = attr->get_namespace_prefix( ).
value = attr->get_value( ).
WRITE: / 'ATTRIBUTE:'.
WRITE: AT indent name COLOR COL_HEADING INVERSE, '=',
value COLOR COL_TOTAL INVERSE.
ENDDO.
ENDIF.
WHEN if_ixml_node=>co_node_text OR
if_ixml_node=>co_node_cdata_section.
text node
value = node->get_value( ).
WRITE: / 'VALUE :'.
WRITE: AT indent value COLOR COL_GROUP INVERSE.
ENDCASE.
advance to next node
node = iterator->get_next( ).
ENDWHILE.
ENDFORM. "process_dom
Section 3: My XSLT file:
<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:template match="TransList">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Tcode">
Tcode <xsl:apply-templates />
</xsl:template>
<xsl:template match="ttext">
ttext <xsl:apply-templates />
</xsl:template>
<xsl:template match="sprsl">
sprsl <xsl:apply-templates />
</xsl:template>
</xsl:transform>The exact error message I'm getting is :
ABAP XML formatting error in XML node of type "element", name: "abap" -
Help Please ! -- transform XML to HTML using xslt tag in JSP
Hello,
I have problem to do XSL transform in JSP.
I have an XSL : test.xsl
I have an XML : test.xml
In JSP I have:
<x:xslt media="html" xml="test.xml">
<x:stylesheet media="html" uri="test.xsl" />
</x:xslt>
But It doesn't work the way it suppose to. What is wrong in my code ? I followed the URL http://e-docs.bea.com/wls/docs81/xml/xml_apps.html
Thanks in advance,
ChristinaBasically:
try{
//Setting up parameters.
xml=new StreamSource(new File(xmlInput));
xsl=new StreamSource(new File(xslInput));
baos=new ByteArrayOutputStream();
htmlResult=new StreamResult(baos);
//Transform input(xml, xsl) onto html output.
TransformerFactory tfactory=TransformerFactory.newInstance();
Transformer transformer=tfactory.newTransformer(xsl);
transformer.transform(xml, htmlResult);
baos.writeTo(out);
//System.err.println(htmlResult.getOutputStream().toString());
catch(...){
}I havent tested and I havent use this for a while, but I hope this can serve as a staring point.
Regards,
OO -
Sending XML from ABAP using WEB Service 6.20 to an external server
Hi,
Can anyone help me to send XML file from WAS 6.20 using ABAP withouut XI?
I am trying to send an XML file to an external server from ABAP. I have created the RFC destination in SM59 with address. I am able to make connection to the host but the whole XML file is not delivered to the receiving.
Thanks,
Wilsonif you want to push, then the other system should have some mechanism to receive it, they can be ftp location, http point, or a webservice. check with external system what do they support.
based on what the external system can support , we can come up with further suggestions. -
Read SOAP envelope into ABAP using XSLT?
Hello,
I have another problem here and this is really driving me nuts - I just don't get it to work.
As a reply to a web-service I call I get the following xml file. All I need is an xslt that gets me errorCode and errorDescription into an ABAP structure...
file:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<mit:rgo xmlns:mit="http://myurl.com"><mit:TECHNICALHEADER><mit:errorCode>A1014</mit:errorCode><mit:errorDescription>Unable to perform operation</mit:errorDescription><mit:password/><mit:user/><mit:applicationKey/></mit:TECHNICALHEADER><mit:file_creation_date>2005-09-06</mit:file_creation_date><mit:file_creation_time>15:06:33.0</mit:file_creation_time><mit:registration><mit:order_nr>DE999TEST</mit:order_nr><mit:vin>XXXXXXXXXXXXXXX04</mit:vin></mit:registration></mit:rgo> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
my corresponding XSLT is:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:mit=
"http://myurl.com" xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap>
<asx:values>
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<mit:rgo>
<mit:TECHNICALHEADER>
<ANSWER>
<mit:errorCode>
<xsl:value-of select="ERRORCODE"/>
</mit:errorCode>
<mit:errorDescription>
<xsl:value-of select="ERRORCODEDESCRIPTION"/>
</mit:errorDescription>
</ANSWER>
</mit:TECHNICALHEADER>
</mit:rgo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>
What am I doing wrong or what do I need to do? I'm lost!
Thank you for your help!
Johannes.Thank you Durairaj, as a matter of fact my program is based on your post (one that you pointed me to). For whatever reason I'm not having luck figuring it out (may be just a bit of work pressure) could you please hlep me a bit more by pointing me to where in my program code/xslt I'm going wrong? I somehow feel that it could be my table structure or xslt.
I would really appreciate it!
Thanks again,
erfan. -
XML to string using xslt or java mapping
Hi Experts,
I want to put xml into string and i need to change lessthan symbol to "<" and greaterthan symbol to ">" , can anyone please help me how to do this??? can you provide code for java mapping or XSLT mapping to achive this.
SOURCE
<?xml version="1.0" encoding="UTF-8"?>
<ns0:source_mt xmlns:ns0="urn:ppp:prototype">
<row>
<name1>IT</name1>
<name2>SOLUTIONS</name2>
</row>
</ns0:source_mt>
TARGET
<?xml version="1.0" encoding="UTF-8"?>
<ns0:target_mt xmlns:ns0="urn:ppp:prototype">
<row>
<Body>"<"name1">" IT"<"/name1">" "<"name2">" SOLUTIONS"<";/name2">" </Body>
</row>
</ns0:target_mt>Hi ,
here is the XSLT code to obtain the desired output
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<ns0:target_mt xmlns:ns0="urn:ppp:prototype">
<xsl:for-each select="//row">
<row>
<Body>
<xsl:for-each select="name1">
<xsl:value-of select="concat('*"<"name1">"*',normalize-space(.),'*"<"/name1">"*')"></xsl:value-of>
</xsl:for-each>
<xsl:for-each select="name2">
<xsl:value-of select="concat('*"<"name2">"*',normalize-space(.),'*"<"/name2">"*')"></xsl:value-of>
</xsl:for-each>
</Body>
</row>
</xsl:for-each>
</ns0:target_mt>
</xsl:template>
</xsl:stylesheet>
output produced as viewed in browser is
http://postimage.org/image/1lqbgw8kk/
Now to obtain exactly the output you posted earlier here is the code
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<ns0:target_mt xmlns:ns0="urn:ppp:prototype">
<xsl:for-each select="//row">
<row>
<Body>
<xsl:for-each select="name1">
<xsl:value-of select="concat('*"&lt"name1"&gt"*',normalize-space(.),'*"&lt"/name1"&gt"*')"></xsl:value-of>
</xsl:for-each>
<xsl:for-each select="name2">
<xsl:value-of select="concat('*"&lt"name2"&gt"*',normalize-space(.),'*"&lt"/name2"&gt"*')"></xsl:value-of>
</xsl:for-each>
</Body>
</row>
</xsl:for-each>
</ns0:target_mt>
</xsl:template>
</xsl:stylesheet>
output you can see from link below
http://postimage.org/image/2c7bzo478
Hope this helps.
Hi,
Could you please kindly let us know if the solution is working properly as per your requirement?
regards
Anupam
Edited by: anupamsap on Jul 26, 2011 6:29 AM
Edited by: anupamsap on Jul 26, 2011 4:10 PM -
Remove xml declarations when using xslt
Hi, i have created an xslt which transforms an xml file and then imports the information into a mysql database. It works and imports the information into the database but it also brings across the xml delcarations and the node names.
Is there a coldfusion way to remove these declarations, all i want is the information itself brought into the database.
Thanks
ChrisHi Adam,
here is the code from the xsl file:
<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="data/itemfeed.xml" --><!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
<!ENTITY copy "©">
<!ENTITY reg "®">
<!ENTITY trade "™">
<!ENTITY mdash "—">
<!ENTITY ldquo "“">
<!ENTITY rdquo "”">
<!ENTITY pound "£">
<!ENTITY yen "¥">
<!ENTITY euro "€">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<xsl:for-each select="Items/Item[ItemType='Standard']">
<xsl:value-of select="EANNumber"/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
And here is some sample data from the XML file:
<?xml version="1.0" encoding="UTF-8" ?>
<Items>
<Item>
<ItemType>Standard</ItemType>
<EANNumber>111222333444</EANNumber>
</Item>
</Items>
Thanks alot, i appreciate the help.
Chris -
Using XSLT to link XML and ABAP data
Hi Experts,
I am using XSLT to deal with XML and ABAP data.
I using the following statement to convert a Internal Table to XML String:
CALL TRANSFORMATION id SOURCE root = lt_sflight RESULT XML l_xml_string.
And I get the XML String:
<?xml version="1.0" encoding="utf-16" ?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ROOT>
<SFLIGHT>
</SFLIGHT>
<SFLIGHT>
</SFLIGHT>
</ROOT>
</asx:values>
</asx:abap>
But What I expected is:
<?xml version="1.0" encoding="utf-16" ?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ROOT>
<DATA>
</DATA>
<DATA>
</DATA>
</ROOT>
</asx:values>
</asx:abap>
Could you tell me how to get my dream format using XSLT?
Best Regards,
Guo Guo Qing
Edited by: guoqing guo on Jun 11, 2008 9:58 AMHi Experts,
I am using XSLT to deal with XML and ABAP data.
I using the following statement to convert a Internal Table to XML String:
CALL TRANSFORMATION id SOURCE root = lt_sflight RESULT XML l_xml_string.
And I get the XML String:
<?xml version="1.0" encoding="utf-16" ?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ROOT>
<SFLIGHT>
</SFLIGHT>
<SFLIGHT>
</SFLIGHT>
</ROOT>
</asx:values>
</asx:abap>
But What I expected is:
<?xml version="1.0" encoding="utf-16" ?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ROOT>
<DATA>
</DATA>
<DATA>
</DATA>
</ROOT>
</asx:values>
</asx:abap>
Could you tell me how to get my dream format using XSLT?
Best Regards,
Guo Guo Qing
Edited by: guoqing guo on Jun 11, 2008 9:58 AM -
XML to Internal table using XSLT by CALL TRANSFORMATION error
Dear experts,
I have to fetch the data from an XML file using XSLT into internal tables. The XML file is very big as following:-
<?xml version="1.0" standalone="yes" ?>
- <Shipment>
<shipmentID>25091203S000778</shipmentID>
<manifestDateTime>2009-12-03T20:16:52.00</manifestDateTime>
<shipmentFacilityNumber>025</shipmentFacilityNumber>
<shipmentFacilityAbbreviation>CHI</shipmentFacilityAbbreviation>
<shipmentFacilityAddress1>810 KIMBERLY DRIVE</shipmentFacilityAddress1>
<shipmentFacilityAddress2 />
<shipmentFacilityCity>CAROL STREAM</shipmentFacilityCity>
<shipmentFacilityState>IL</shipmentFacilityState>
<shipmentFacilityPostalCode>601880000</shipmentFacilityPostalCode>
<shipmentTruckCarrierCode>X150</shipmentTruckCarrierCode>
<shipmentSourceCode>T</shipmentSourceCode>
<userID>CAMPOSG</userID>
- <Delivery>
<primaryCustomerNumber>954371</primaryCustomerNumber>
<primaryCustomerName>MIDWEST OFFICE SUPPLY</primaryCustomerName>
<primaryCustomerAddress1 />
<primaryCustomerAddress2>4765 INDUSTRIAL DR</primaryCustomerAddress2>
<primaryCustomerCity>SPRINGFIELD</primaryCustomerCity>
<primaryCustomerState>IL</primaryCustomerState>
<primaryCustomerPostalCode>627030000</primaryCustomerPostalCode>
<primaryCustomerPhoneNumber>2177535555</primaryCustomerPhoneNumber>
<shuttleStopFacilityNumber />
<billOfLadingNumber>25HZK99</billOfLadingNumber>
<carrierProNumber />
<shipmentTotalCartonCount>6</shipmentTotalCartonCount>
<shipmentTotalWeight>266</shipmentTotalWeight>
- <order>
<orderNumber>25HZK99</orderNumber>
<subOrderNumber />
<dateProcessed>2009-12-03</dateProcessed>
<primaryOrderNumber />
<shipTruckCode>X150</shipTruckCode>
<shipTruckDescription>UDS - ADDISON</shipTruckDescription>
<shipTruckPriorityCode>01</shipTruckPriorityCode>
<shipTruckGroupCode>01</shipTruckGroupCode>
<shipTruckDepartureTime>20.00.00</shipTruckDepartureTime>
<shipTruckDockID>07</shipTruckDockID>
<ldpFacilityAbbreviation />
<shuttleAvailableIndicator>N</shuttleAvailableIndicator>
<shuttleMessageText />
<crossDockFacilityCode />
<crossDockTruckCode />
<crossDockID />
<subsidizedFreightTruckID />
<customerPurchaseOrderNumber>623559</customerPurchaseOrderNumber>
<headerTypeCode>P</headerTypeCode>
<orderTypeID>RG</orderTypeID>
<deliveryTypeID>DS</deliveryTypeID>
<deliveryMethodCode />
<customerBarCode />
<customerReferenceData>25HZK99</customerReferenceData>
<customerReferenceText />
<customerRouteData>ZNED UNTED</customerRouteData>
<customerRouteText>ROUTE</customerRouteText>
<endConsumerPurchaseOrderNumber />
<endConsumerPurchaseOrderText />
<endConsumerName>CHARLESTON TRANS. FACILITY</endConsumerName>
<endConsumerAddress1>HOMEWOOD DT PROGRAM DEPT. 3</endConsumerAddress1>
<endConsumerAddress2>17341 PALMER BLVD.</endConsumerAddress2>
<endConsumerAddress3 />
<endConsumerCity>HOMEWOOD</endConsumerCity>
<endConsumerState>IL</endConsumerState>
<endConsumerPostalCode>60430</endConsumerPostalCode>
<endConsumerCountryCode />
<fillFacilityNumber>025</fillFacilityNumber>
<shpFacilityNumber>025</shpFacilityNumber>
<homeFacilityAbbrCode>STL</homeFacilityAbbrCode>
<homeFacilityNumber>015</homeFacilityNumber>
<multiCartonIndicator>Y</multiCartonIndicator>
<primaryCustomerIndicator>Y</primaryCustomerIndicator>
<shipToCustomerNumber>954371001</shipToCustomerNumber>
<customerCompanyID>01</customerCompanyID>
<customerTruckID>U888</customerTruckID>
<customerTruckDescription>UDS - ADDISON</customerTruckDescription>
<customerTruckDockID>13</customerTruckDockID>
<thirdPartyBillCarrier />
<thirdPartyBillID />
<thirdPartyBillType />
<qualityCheckIndicator>N</qualityCheckIndicator>
<warehouseLaydownID />
<packListPosition>I</packListPosition>
<preferredPackingType>CTN</preferredPackingType>
<preferredPackingMaterial>PAPER</preferredPackingMaterial>
<preferedPackingInstructions />
<totalOrderCartonQty>6</totalOrderCartonQty>
<convertAddressIndicator>N</convertAddressIndicator>
<dealerInstructionIndicator>Y</dealerInstructionIndicator>
<dealerinstructions1>CPO#: 623559</dealerinstructions1>
<dealerinstructions2>ATTN: DANA GRIFFIN</dealerinstructions2>
<dealerinstructions3>INFO: 612</dealerinstructions3>
<dealerinstructions4>ROUTE: ZNED UNTED</dealerinstructions4>
<dealerinstructions5 />
<dealerinstructions6 />
<shippingInstructionsIndicator>N</shippingInstructionsIndicator>
<shippingInstructions1 />
<shippingInstructions2 />
<shippingInstructions3 />
<shippingInstructions4 />
<shippingInstructions5 />
<shippingInstructions6 />
<specialInstructionsIndicator>N</specialInstructionsIndicator>
<specialInstructions1 />
<specialInstructions2 />
<customeContainerDesc />
- <carton>
<deliveryCartonID>253370905995</deliveryCartonID>
<shipIndicator>Y</shipIndicator>
<deliveryPalletID>X150</deliveryPalletID>
<consolidatedDeliveryCartonID />
<scanDateTime>2009-12-03T19:36:12.00</scanDateTime>
<cartonWeight>52</cartonWeight>
<dropShipFlag>1</dropShipFlag>
<carrierTrackingNumber />
<carrierZoneID>0</carrierZoneID>
<codAmount />
<customerPackageAmount />
<declaredValue />
<residentialDeliveryIndicator />
<serviceTypeCode>00</serviceTypeCode>
<ssccCode>006860244400829393</ssccCode>
- <Item>
<shipPrefix>UNV</shipPrefix>
<shipStockNumber>21200</shipStockNumber>
<itemDescription>PAPER XERO/DUP WE LTR 20#</itemDescription>
<orderQuantity>1</orderQuantity>
<originalShipQuantity>1</originalShipQuantity>
<shipQuantity>1</shipQuantity>
<inventoryUnitCode>CT</inventoryUnitCode>
<inventoryWeightQuantity>52.000</inventoryWeightQuantity>
<upcNumber>00000000000000</upcNumber>
<upcRetailCode>087547212004</upcRetailCode>
<hazmatIndicator>N</hazmatIndicator>
<serialRequiredIndicator>N</serialRequiredIndicator>
<dealerMemoPO>S</dealerMemoPO>
<cartonLineNumber>1</cartonLineNumber>
<orderLineNumber>11</orderLineNumber>
<originalOrderPrefix>UNV</originalOrderPrefix>
<originalOrderStockNumber>21200</originalOrderStockNumber>
<reasonCode />
- <Item_Serial>
<serialNumber />
</Item_Serial>
</Item>
</carton>
</order>
</Delivery>
</Shipment>
This is not the complete XML file as it exceeds the 15000 characters and then I cann't post here. So I have deleted much part of it.
The hierarchy is as following: Shipment->Delivery->Order->Carton->Item.
I have created a XSLT for it which is working fine.
But when I execute my report program it gives CX_SY_XSLT_FORMAT_ERROR saying that
Transformation error: Non-canonical structure of element name XML_OUTPUT.Dear experts,
My report program is as following:-
*& Report Z_ASNTRNS
REPORT Z_ASNTRNS.
*& Report Z_ASNTRNS
TYPE-POOLS: abap, ixml.
TABLES: ZASN_SHIPMENT,ZASN_DELIVERY,ZASN_ORDER,ZASN_CARTON,ZASN_ITEM.
*CONSTANTS gs_file TYPE string VALUE 'C:Documents and SettingsC5134126DesktopRajesh_kandakatlaSampleASNFile.xml'.
This is the structure for the data from the XML file
TYPES: BEGIN OF ts_item,
ZSHIPMENT LIKE ZASN_ITEM-ZSHIPMENT,
VBELN LIKE ZASN_ITEM-VBELN,
ORDER_NUMBER LIKE ZASN_ITEM-ORDER_NUMBER,
CARTON_ID LIKE ZASN_ITEM-CARTON_ID,
ITEM LIKE ZASN_ITEM-ITEM,
CARTON_LINE_NUM LIKE ZASN_ITEM-CARTON_LINE_NUM,
CARTON_LINE_NUMBER LIKE ZASN_ITEM-CARTON_LINE_NUM,
AEDAT(8),
AEZET(6),
ITEM_DESCRIPTION LIKE ZASN_ITEM-ITEM_DESCRIPTION,
ORD_QTY(16),
ORIGINAL_SHIP(16),
SHIP_QTY(16),
UPC_NUMBER LIKE ZASN_ITEM-UPC_NUMBER,
DEALER_MEMO_PO(5),
ORDER_LINE_NUM LIKE ZASN_ITEM-ORDER_LINE_NUM,
STATUS LIKE ZASN_ITEM-STATUS,
END OF ts_item.
TYPES: BEGIN OF ts_carton,
ZSHIPMENT LIKE ZASN_CARTON-ZSHIPMENT,
VBELN LIKE ZASN_CARTON-VBELN,
ORDER_NUMBER LIKE ZASN_CARTON-ORDER_NUMBER,
CARTON_ID LIKE ZASN_CARTON-CARTON_ID,
AEDAT(8),
AEZET(6),
SHIP_INDICATOR LIKE ZASN_CARTON-SHIP_INDICATOR,
TRACKING_NUMBER LIKE ZASN_CARTON-TRACKING_NUMBER,
ZZCARTON_WGT(18),
Item type ts_item,
END OF ts_carton.
TYPES: BEGIN OF ts_order,
ZSHIPMENT LIKE ZASN_ORDER-ZSHIPMENT,
VBELN LIKE ZASN_ORDER-VBELN,
ORDER_NUMBER LIKE ZASN_ORDER-ORDER_NUMBER,
AEDAT(8),
AEZET(6),
SUB_ORDER LIKE ZASN_ORDER-SUB_ORDER,
ORDER_DATE(8),
PRIMARY_ORDER LIKE ZASN_ORDER-PRIMARY_ORDER,
CUSTOMER_PO LIKE ZASN_ORDER-CUSTOMER_PO,
PRIMARY_ID LIKE ZASN_ORDER-PRIMARY_ID,
SHIP_TO LIKE ZASN_ORDER-SHIP_TO,
ANZPK(5),
carton type ts_carton,
END OF ts_order.
TYPES: BEGIN OF ts_delivery,
ZSHIPMENT LIKE ZASN_DELIVERY-ZSHIPMENT,
VBELN LIKE ZASN_DELIVERY-VBELN,
AEDAT(8) TYPE C,
AEZET(6) TYPE C,
PRIMARY_CUSTOMER LIKE ZASN_DELIVERY-PRIMARY_CUSTOMER,
BILL_OF_LADING LIKE ZASN_DELIVERY-BILL_OF_LADING,
CARTON_COUNT(5),
TOTAL_WEIGHT(18),
order type ts_order,
END OF ts_delivery.
TYPES: BEGIN OF ts_shipment,
ZSHIPMENT LIKE ZASN_SHIPMENT-ZSHIPMENT,
MANIFEST_DATE_TIME(25),
AEDAT(8) TYPE C,
AEZET(6) TYPE C,
SDATE(8) TYPE C,
STIME(6) TYPE C,
SFACILITY_NUMBER LIKE ZASN_SHIPMENT-SFACILITY_NUMBER,
ZZCARRIERCODE LIKE ZASN_SHIPMENT-ZZCARRIERCODE,
Delivery type ts_delivery,
END OF ts_shipment.
TYPES: BEGIN OF ts_shipment1,
ZSHIPMENT LIKE ZASN_SHIPMENT-ZSHIPMENT,
MANIFEST_DATE_TIME(25),
SFACILITY_NUMBER LIKE ZASN_SHIPMENT-SFACILITY_NUMBER,
ZZCARRIERCODE LIKE ZASN_SHIPMENT-ZZCARRIERCODE,
PRIMARY_CUSTOMER LIKE ZASN_DELIVERY-PRIMARY_CUSTOMER,
BILL_OF_LADING LIKE ZASN_DELIVERY-BILL_OF_LADING,
CARTON_COUNT(5),
TOTAL_WEIGHT(18),
ORDER_NUMBER LIKE ZASN_ORDER-ORDER_NUMBER,
SUB_ORDER LIKE ZASN_ORDER-SUB_ORDER,
ORDER_DATE(8),
PRIMARY_ORDER LIKE ZASN_ORDER-PRIMARY_ORDER,
CUSTOMER_PO LIKE ZASN_ORDER-CUSTOMER_PO,
PRIMARY_ID LIKE ZASN_ORDER-PRIMARY_ID,
SHIP_TO LIKE ZASN_ORDER-SHIP_TO,
CARTON_ID LIKE ZASN_CARTON-CARTON_ID,
SHIP_INDICATOR LIKE ZASN_CARTON-SHIP_INDICATOR,
TRACKING_NUMBER LIKE ZASN_CARTON-TRACKING_NUMBER,
ZZCARTON_WGT(18),
ITEM LIKE ZASN_ITEM-ITEM,
CARTON_LINE_NUM LIKE ZASN_ITEM-CARTON_LINE_NUM,
CARTON_LINE_NUMBER LIKE ZASN_ITEM-CARTON_LINE_NUM,
ITEM_DESCRIPTION LIKE ZASN_ITEM-ITEM_DESCRIPTION,
ORD_QTY(16),
ORIGINAL_SHIP(16),
SHIP_QTY(16),
UPC_NUMBER LIKE ZASN_ITEM-UPC_NUMBER,
DEALER_MEMO_PO(5),
ORDER_LINE_NUM LIKE ZASN_ITEM-ORDER_LINE_NUM,
END OF ts_shipment1.
TYPES: BEGIN OF t_xml_line,
data(256) TYPE x,
END OF t_xml_line.
*Typdefinition für Airplus
*READ THE DOCUMENTATION "LASG_XML_INVOICE_BTM"!!!
VARs beginning with "a_" are ATTRIBUTES
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_parser TYPE REF TO if_ixml_parser,
l_istream TYPE REF TO if_ixml_istream,
l_ostream TYPE REF TO if_ixml_ostream,
l_document TYPE REF TO if_ixml_document,
l_node TYPE REF TO if_ixml_node,
l_xml TYPE REF TO cl_xml_document,
l_xmldata TYPE string.
DATA: l_xml_table TYPE TABLE OF t_xml_line,
l_xml_line TYPE t_xml_line,
l_xml_table_size TYPE i.
DATA: l_filename TYPE string.
DATA: xml_out TYPE string ,
size type i.
DATA: l_xml_x1 TYPE xstring.
DATA: l_len TYPE i,
l_len2 TYPE i,
l_tab TYPE tsfixml,
l_content TYPE string,
l_str1 TYPE string,
c_conv TYPE REF TO cl_abap_conv_in_ce.
l_itab TYPE TABLE OF string.
DATA: BEGIN OF l_itab occurs 0,
data(256) type c,
end of l_itab.
TYPES : BEGIN OF TY_TEXT,
data(255) type C,
END OF TY_TEXT.
DATA: F_XML TYPE STRING.
DATA : LT_TEXT_OUT type table of TY_TEXT with header line.
tables
DATA: it_shipment TYPE STANDARD TABLE OF ts_shipment,
wa_shipment TYPE ts_shipment.
*Errorvariables
DATA: xslt_err TYPE REF TO cx_xslt_exception,
err_string TYPE string.
PARAMETERS: pa_file TYPE localfile OBLIGATORY
DEFAULT 'C:Documents and SettingsC5134126DesktopRajesh_kandakatlaSampleASNFile.xml'.
START-OF-SELECTION.
Creating the main iXML factory
l_ixml = cl_ixml=>create( ).
Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
PERFORM get_xml_table CHANGING l_xml_table_size l_xml_table.
here we use the CALL TRANSFORMATION method which calls
the XSLT program "z_asnfile"
TRY.
CALL TRANSFORMATION ('Z_ASNFILE')
SOURCE xml LT_TEXT_OUT[]
RESULT xml_output = it_shipment
catch any error, very helpful if the XSLT isn't correct
CATCH cx_xslt_exception INTO xslt_err.
err_string = xslt_err->get_text( ).
WRITE: / 'Transformation error: ', err_string.
EXIT.
ENDTRY." setting a breakpoint to watch the workarea
by the internal table "it_airplus"
break-point.
LOOP AT it_shipment INTO wa_shipment.
ENDLOOP.
*& Form get_xml_table
FORM get_xml_table CHANGING l_xml_table_size TYPE i
l_xml_table TYPE STANDARD TABLE.
l_filename = pa_file.
upload a file from the client's workstation
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = l_filename
filetype = 'BIN'
IMPORTING
filelength = l_xml_table_size
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Convert binary to text.
CALL FUNCTION 'SCMS_BINARY_TO_TEXT'
EXPORTING
INPUT_LENGTH = 70000
FIRST_LINE = 0
LAST_LINE = 0
APPEND_TO_TABLE = ' '
MIMETYPE = ' '
WRAP_LINES = 'X'
IMPORTING
OUTPUT_LENGTH =
TABLES
BINARY_TAB = l_xml_table
TEXT_TAB = LT_TEXT_OUT
EXCEPTIONS
FAILED = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "get_xml_table -
To convert XML to ABAP internal table can we do it with DOM or we need XSLT
I have a requirement where I need to collect the data from XML file into an internal table.
I need to collect this data into an internal table as I should make use of this data and do Goods Receipt in SAP.
My XML file is very very complex and the child nodes in my XML file may occur ones or 10 times and change dynamically.
I want to know if XML to ABAP internal table is possible with DOM or does it need XSLT too.
I used the blog of Robert which uses DOM, but it I am unable to collect the data in internal table. The blog explains only how to wtite the out put to screen as element and value.
I want to know if XML to ABAP internal table is possible with DOM or do I need XSLT too? I am confused please help.
Any help will be highly appreciated.
Regards,
Jessica SamHello Jessica
Why not using the DOM itself for processing?
Below you see the post-processing coding which I use to add the interchange control number (ICN) into an EDI message (which at this stage is still an XML-EDI stream). This is done on SAP-XI yet on the ABAP stack so you could use this approach on your R/3 system as well.
method POSTPROCESSING.
* Post-Processing of outbound EDI invoices & dispatch advices
me->map_icn( ).
endmethod.
method MAP_ICN.
* define local data
DATA: lo_node TYPE REF TO if_ixml_node,
ld_name TYPE string,
ld_value TYPE string,
ld_error_code type MPG_ERRCODE,
** ld_control_number TYPE char13,
ld_rc TYPE i,
ld_msg TYPE string. " bapi_msg.
DATA: ld_interface TYPE string.
DATA: incode TYPE REF TO if_ixml_node_collection.
LOG-POINT ID zedi
SUBKEY mc_subkey_method_trace.
ld_error_code = md_clsname.
* Get next interchange control number (ICN)
me->md_next_number = me->get_next_number(
id_nrobj = me->md_nrobj " Object (SNRO)
id_nrnr = me->md_nrnr ). " Number Range
CALL METHOD zcl_edi_uk_counter=>calculate_modulo_n09
EXPORTING
id_input = me->md_next_number
receiving
rd_output = me->md_next_number.
* Build ICN according to naming conventions agreed with EDI customer
me->md_icn = me->generate_icn( me->md_next_number ).
ld_value = me->md_icn. " type conversion to string
CLEAR: incode,
lo_node.
incode = me->mo_document->get_elements_by_tag_name( mc_d_0020 ).
lo_node = incode->get_item( index = 0 ).
CALL METHOD lo_node->set_value
EXPORTING
value = ld_value
RECEIVING
rval = ld_rc.
IF ( ld_rc NE 0 ).
CONCATENATE 'Error [' mc_d_0020
']: Method SET_VALUE (IF_IXML_NODE)'
INTO ld_msg.
CONDENSE ld_msg.
me->mif_trace->trace2( message = ld_msg ).
RAISE EXCEPTION TYPE cx_mapping_fault
EXPORTING
* textid =
* previous =
error_code = ld_error_code
error_text = ld_msg.
** MESSAGE ld_msg TYPE 'A'.
ENDIF.
CLEAR: incode,
lo_node.
incode = me->mo_document->get_elements_by_tag_name( mc_d_0020_2 ). " element for ICN
lo_node = incode->get_item( index = 0 ).
CALL METHOD lo_node->set_value
EXPORTING
value = ld_value
RECEIVING
rval = ld_rc.
IF ( ld_rc NE 0 ).
CONCATENATE 'Error [' mc_d_0020_2
']: Method SET_VALUE (IF_IXML_NODE)'
INTO ld_msg.
CONDENSE ld_msg.
me->mif_trace->trace2( message = ld_msg ).
RAISE EXCEPTION TYPE cx_mapping_fault
EXPORTING
* textid =
* previous =
error_code = ld_error_code
error_text = ld_msg.
** MESSAGE ld_msg TYPE 'A'.
ENDIF.
* define local data
DATA: ls_record TYPE mpp_dynamic.
CLEAR: ls_record.
ls_record-namespace = mc_dynamic_namespace.
ls_record-name = mc_icn.
ls_record-value = ld_value.
mif_dynamic->add_record( ls_record ).
endmethod.
In your case you would need to do a DO...ENDDO loop until you parsed all required nodes.
NOTE: ME->MO_DOCUMENT is of TYPE REF TO IF_IXML_DOCUMENT.
Regards
Uwe -
How to update XML file using XSLT
Hi there,
I have a "small" issue with exporting data to an XML file using XSLT.
A two steps process is needed to import data from a non-hierarchical XML file into ABAP, change the data, and then update the XML file with new values. The problem is not trivial, since the format of the XML file is a complex one: there are many interdependent elements on the same level, pointing to each other by using id and ref attributes. Based on these values the data can be read and written into an internal table. I use XSLT and XPath for that. So the inbound process is done and seems to work correctly. I have to mention that the file contains much more data than I need. I am working only with a small part of it.
Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT? I can pass only the internal table to the transformation, so how do I access the XML file in order to update it? I have tried to use the <B>xsl:document()</B> function to access the content of the file store locally on my PC, but it fails each time by throwing and URI exception. I have tried the absolute path without any addition and the path with the file:/// addition. Same result. Please advise.
Many thanks,
Ferenc
P.S. Please provide me with links only if they are relevant for this very matter. I will not give points for irrelevant postings...Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT?
XSLT approach: check these online tutorial
http://www.xml.com/pub/a/2000/08/02/xslt/index.html
http://www.xml.com/pub/a/2000/06/07/transforming/index.html
ABAP approach:
for example you have the xml (original) in a string called say xml_out .
data: l_xml type ref to cl_xml_document ,
node type ref to if_ixml_node .
create object l_xml.
call method l_xml->parse_string
exporting
stream = xml_out.
node = l_xml->find_node(
name = 'IDENTITY'
ROOT = ROOT
l_xml->set_attribute(
name = 'Name'
value = 'Charles'
node = node
(the above example reads the element IDENTITY and sets attribute name/value to the same)
like wise you can add new elements starting from IDENTITY using various methods available in class CL_XML_DOCUMENT
so how do I access the XML file in order to update it?
you have already read this XML into a ABAP variable right?
Sorry couldnt understand your whole process, why do you need to read local XML file?
Raja
Maybe you are looking for
-
Ok all knowing people, I have this working in EP5 but, can't get it working in EP6. Our Portal: EP6 SP2 Pack3 Hotfix7. Working like a champ. However, SSO to our ITS box will not work. I have downloaded and am using the SAP application integrator.
-
Hello! I wonder if anyone could help me with my navigations buttons... I am trying to create buttons with images I have created with photoshop in a way that tthey behave like this: "up" stage with one image, the "over" stage with another image and I
-
BAPi to approve service entry sheet
Hi All, I want to approve a service entry sheet I am using the BAPi - BAPI_ENTRYSHEET_CREATE, I am able to create a service entry sheet but unable to approve it. Please let me know if there is a BAPi- for approving a service entry sheet. Regards Shiv
-
I have a contact in Skype account where I see an unknown number in his account only when viewed from my account. I synced my Skype account in Windows Phone so I get two numbers for this contact. We logged in his Skype account profile and there is onl
-
Hi , Can Anyone please tell the function module for POPUP with check box. Thanks & Regards Ruchi Tiwari