Help for supporting XML, XSLT, and Simple Transformations

[] [] [] []

Symptom

This internal note is intended to help SAP employees to understand customer problems in the area of serializing and deserializing XML in ABAP programs. The aim of this is to reduce processing time and to identify the component responsible for processing.

Reason and Prerequisites

In an application program, the XML data is processed incorrectly.
Solution

The component BC-ABA-XML provides support for the following subject areas and technologies:
Using ABAP to serialize and deserialize XMLasXMLCALL TRANSFORMATION (ABAP language command)XSL/XSLTSimple TransformationsiXML library (classes in the package SIXML)fxreader/fxwriter (streamed XML reader/writer in the package SXML)

From time to time, the system may encounter an error in one of these technologies. Therefore, you must always check whether a note already exists to solve this error. Often, the customer can install the current kernel to solve the problem.
Frequently, messages are assigned to the component BC-ABA-XML even though they have little to do with the XML topic. You must forward these messages to the component that is responsible to ensure that they are processed quickly. Here are some examples:
A short dump or a core dump (for example, signal 11) occurs in the Web service because a Simple Transformation program was generated incorrectly.Forward this to the component BC-ESI-WS-ABA.Questions about and problems with Web services and proxies.Forward this to the component BC-DWB-PRX.Questions about and problems with Web services and the Web Services Description Language (WSDL) (for example, problems with serializing or deserializing Web services).Forward this to the component BC-ESI-WS-ABA.Questions about and problems with mapping in the SAP NetWeaver Exchange Infrastructure (XI).Forward this to the component BC-XI-IBD.Questions about and problems with the XI and configuration.Forward this to the component BC-XI-IBC.Messages about creating PDF documents and forms (Adobe forms).Forward this to the component BC-SRV-FP.Messages about IDoc and the IDoc converter.Forward this to the component BC-MID-ALE.

Frequently, you must search for an error in the use of these technologies. For this reason, it is important that you check whether corrections have already been provided for the relevant application. Even if no corrections exist, you must first check the relevant application to see whether the error is in the application. This may reduce the time taken to process the customer message significantly. Here are some typical examples:
An application has problems with different code pages or with Unicode and non-Unicode.Forward this to the application with Note 1017101.An application passes something (that is, not XML) to the XSLT processor and does not catch the exception.Forward this to the application with Note 1017101.An application passes invalid XML documents to the iXML library and does not handle the error; as a result, the exception OBJECTS_OBJREF_NOT_ASSIGNED_NO occurs.Forward this to the application.The iXML library has a cache for strings; this grows continually and cannot be deactivated. This may cause a memory bottleneck.Forward this to the application with Note 1081257.Instead of the include IXML_GLOBAL, an application uses the includes BCCIIXML_DECL and BCCIIXML_IMPL. This causes the runtime error “CX_SY_MOVE_CAST_ERROR” in iXML.Forward this to the application with Note 1160906.

This note must always provide the most current information. If messages are forwarded incorrectly due to this note, the note must be adjusted immediately. This can be done only if you inform the author or if you correct the note yourself.
In addition, the component BC-ABA-XML often receives consulting requests. You can often help in this situation by providing references to documentation. You can also sometimes help the customer by providing a small example program. This is often clearer than the existing documentation and the customer will pay for it. You can find examples of this in customer messages that have already been solved. Therefore, it makes sense to search for problem messages that have already been solved in the component BC-ABA-XML. Here are some examples:
The customer wants to use XSLT to create a CDATA section.Only the iXML library can be used to create a CDATA section.XSLT how-to requestSee message 877185 2008.

XML terminology

Here is a short, incomplete introduction to the terminology that is used in connection with the component BC-ABA-XML. In general, only a link to a good explanation is provided to avoid going beyond the scope of this note.
XML = Extensible Markup LanguageWikipedia -> XMLhttp://www.w3.org/XML/1999/XML-in-10-points.html.enhttp://www.w3.org/XMLhttp://www.w3schools.com/xml/default.aspXML namespacesWikipedia -> namespaces (XML)http://www.w3.org/XML/1999/XML-in-10-points.html.enhttp://www.w3schools.com/xml/xml_namespaces.aspXML encodingUseful notes: 1017101BOM = Byte Order MarkWikipedia -> Byte Order MarkUseful notes: 1017101XML CData sectionWikipedia -> CDATAhttp://www.w3schools.com/xml/xml_cdata.aspXML schemaWikipedia -> XML schemahttp://www.w3schools.com/Schema/schema_why.aspWell-formed XMLFor each open XML tag, there must be a closing XML tag. Only then is an XML document well-formed and meets the minimum prerequisite for processing by an XML parser (for example, an XSLT processor).http://www.w3schools.com/xml/xml_dtd.aspValid XMLThe content of an XML document is checked against a rule (schema validation), for example, whether all of the required tags are filled. An XML document is valid if the check runs successfully.http://www.w3schools.com/xml/xml_dtd.aspOnly iXML supports DTD (Document Type Definition) for validation.XSD (XML Schema Definition) is not supported.DOM = Document Object ModelWikipedia -> Document Object Modelhttp://www.w3schools.com/xml/xml_dom.aspXML transformationThe rendering or parsing of XML data, or the serialization and deserialization of XML data.XSLT = Extensible Stylesheet LanguageWikipedia -> XSL Transformationhttp://www.w3schools.com/xsl/XML serialization/renderingThe transformation of data in ABAP data structures into XML, for example, into an xstring or directly into a file.When using iXML, serialization refers to the transformation of data from the document object model (DOM) into an XML document.XML deserialization/parsingThe transformation of data in an XML document into data structures in ABAP programs, for example, from an xstring or directly from a file.When using iXML, deserialization refers to the transformation of data from an XML document into the DOM.asXML = ABAP Serialization XMLThis is the short name for the canonical XML representation of ABAP data. This canonical XML representation is used internally during serialization and deserialization.

XML Transactions
STRANSXSLT programs and SIMPLE TRANSFORMATION programs are maintained using transaction STRANS.SE80XSLT programs and SIMPLE TRANSFORMATION programs are also supported by the ABAP Workbench (transformations).SSTDEMO1This is a test program for Simple Transformations.SSTDEMO2This is a test program for Simple Transformations and XSLT.

XML test programs
The program TST_CL_FX_READER tests the FX_READER.

SAP XML technologies
ABAP statement CALL TRANSFORMATIONYou can use CALL TRANSFORMATION to call the XSLT and SIMPLE TRANSFORMATIONS programs to perform a serialization or deserialization of XML data.XSLT processor (standard) as of Release 6.10XSLT is a DOM-based XML parser. This enables optional access to the source data.When this XSLT processor was implemented, the current specification for XSLT 2.0 was not yet approved. Therefore, this implementation complied with the “W3C Working Draft” of April 30, 2002. In addition, there are some SAP proprietary enhancements.Useful notes: 1298753Simple Transformation processor (SAP proprietary) as of Release 6.40.A Simple Transformation (ST) program always accesses the source data in a strictly linear manner. An ST program is therefore more efficient in terms of runtime and memory consumption. However, it provides limited features compared to XSLT. Since no DOM is set up, optional access to the source data is not possible, for example.iXML Library (package SIXML) as of Release 4.6DThe iXML library contains various ABAP classes for parsing and rendering XML documents or HTML documents. iXML uses a DOM to display the data in the main memory.Useful notes: 1081257, 1229110, 1232514FX_READER/FX_WRITER (package SXML)Classes for parsing and rendering XML documents. If possible, you should no longer use these classes.SXML (package SXML) as of Release 7.00The SXML library contains various ABAP classes and interfaces for parsing and rendering XML documents. With the availability of the SXML library, you should no longer use the FX_READER/FX_WRITER classes.
KW documentation (online documentation for customers)
XML library: http://aiokeh.wdf.sap.corp:1080/SAPIKS2/contentShow.sap?_CLASS=IWB_EXTHLP& TMP_IWB_TASK=DISPLAY&_SLOIO=4CB5413ACDB62F70E10000000A114084& _LOIO=47B5413ACDB62F70E10000000A114084&LANGUAGE=DE&RELEASE=700&_SCLASS=IWB_STRUCTSimple Transformations: http://aiokeh.wdf.sap.corp:1080/SAPIKS2/contentShow.sap?_SCLASS=IWB_STRUCT& _LOIO=E37D4719CA581441B6841F1054FF1326&TMP_IWB_TASK=DISPLAY&RELEASE=710&LANGUAGE=EN&_SEQNUM=0XSLT Debugger: http://aiokeh.wdf.sap.corp:1080/SAPIKS2/contentShow.sap?_CLASS=IWB_EXTHLP& _LOIO=7884353C9A70A57BE10000000A11402F&&TMP_IWB_TASK=DISPLAY&RELEASE=710&LANGUAGE=ENSAP XSLT processor reference: http://aiokeh.wdf.sap.corp:1080/SAPIKS2/contentShow.sap?_CLASS=IWB_EXTHLP& _LOIO=A8824C3C66177414E10000000A114084&&TMP_IWB_TASK=DISPLAY&RELEASE=710&LANGUAGE=ENiXML ABAP Objects jump-start:http://aiokeh.wdf.sap.corp:1080/SAPIKS2/contentShow.sap?_CLASS=IWB_EXTHLP& _LOIO=868280BA12D511D5991B00508B6B8B11&&TMP_IWB_TASK=DISPLAY&RELEASE=710&LANGUAGE=EN

Documentation and training about XML that is generally available

Books
XML Data Exchange Using ABAP ( Galileo Press / ISBN 978-1-59229-076-5)Many books about XML and XSLT 1.0 are available in shops.

Recommended Web sites that are freely available
W3C: http://www.w3.orgNamespaces in XML 1.0: http://www.w3.org/TR/2006/REC-xml-names-20060816Document Object Model(DOM): http://www.w3.org/DOMExtensible Markup Language(XML): http://www.w3.org/XMLThe Extensible Stylesheet Language Family(XSL): http://www.w3.org/Style/XSLXSL Transformations(XSLT) Version 1.0: http://www.w3.org/TR/xsltXML Path Language(XPath) Version 1.0: http://www.w3.org/TR/xpathW3 Schools: http://www.w3schools.comXML Tutorial: http://www.w3schools.com/xml/default.aspXML DOM Tutorial: http://www.w3schools.com/dom/default.aspXSLT Tutorial: http://www.w3schools.com/xsl/default.aspXSLT Elements Reference: http://www.w3schools.com/xsl/xsl_w3celementref.aspXPath Tutorial: http://www.w3schools.com/xpath/default.asp

Useful notes

General topics
1017101 Encoding Problems with ABAP XML Processing1229110 Lack of memory when working with large amounts of XML data

XSL/XSLT
1150513 SAP XSLT and XPath implementation451631 SAP XSLT: Conformance, Restrictions, Extensions421802 Upper/lower case with CALL TRANSFORMATION1312657 RUNT_INTERNAL_ERROR when you debug an XSL transformation1298753 Problems with XSL statement
iXML
1081257 Memory leak in the iXML library1160906 CX_SY_MOVE_CAST_ERROR when using iXML1232514 iXML output stream is closed after CALL TRANSFORMATION819976 iXML “SAP-” encoding1041732 iXML: Process hangs up

FX reader/FX writer
981165 Downport dataset reader/writer

Tips & Tricks
The transformation ID serializes and deserializes the XML (you can use CALL TRANSFORMATION to call the transformation ID). The format that was used is asXML. You can use the transformation ID for very simple applications.To understand how an XSLT program must be written in order to convert an XML document into ABAP data structures (XML deserialization), you can use the transformation ID to do the opposite (XML serialization) and create XML from the ABAP data structures. The XML document that you obtain is in asXML format. This is often helpful because, for the deserialization, you must use an XSLT program to create this type of asXML document from the specified XML document. The asXML format is an intermediate format which the ABAP language command CALL TRANSFORMATION uses to exchange the data with the ABAP data structures. In addition, in an XML serialization, an XSLT program operates using this asXML interim format and not directly in the ABAP data structures. The reason for this procedure is the design of XSLT.To debug an XSLT program, you must use transaction STRANS to set a breakpoint in the XSLT program. Optionally, you can also set a breakpoint on the relevant CALL TRANSFORMATION statement in the ABAP program. When the system reaches the breakpoint in the XSLT program, it calls the XSLT Debugger automatically.You can use the new Debugger to display XML data in an HTML viewer. Therefore, you can check whether a field contains a valid XML document. When you double-click the relevant field, you navigate to the detail display; here you can switch to the “XML Browser” view. If an error occurs, the HTML control cannot display the XML document.To discover problems with the encoding (code page) of XML data, you can proceed as described in the previous example and, in the detail display in the new Debugger, you can switch to the “Text Translation” view. Here, you can change the code page to test whether the data exists as expected in a different code page.In the text translation display, if the system cannot display the first two to four bytes, this almost certainly indicates a Byte Order Mark (BOM). You can find useful documentation about the BOM on the internet (for example, on Wikipedia). The system uses the values in the BOM to recognize the code page that is used and these values must correspond to the encoding that is used. Below are a few examples of entries in the BOM in hexadecimal format:EF BB BF UTF-8FE FF UTF-16 Big EndianFF FE UTF-16 Little Endian00 00 FE FF UTF-16 Big EndianFF FE 00 00 UTF-16 Little EndianA range of test programs are available to check whether the XML documents are correct. You can also use these programs to test the XML framework.The program TST_CL_FX_READER uses the fxreader to parse an XML document.The program T_PARSING_FILE uses the iXML library, checks more strictly, and provides options for checking and displaying the data.The package SIXML_TEST contains a variety of test programs.You can use transaction SSTDEMO1 to test Simple Transformations.You can use transaction SSTDEMO2 to test XSLT and Simple Transformations. You can display the source code of the transformations for the predefined examples. You use XSLT to create an XML document or an HTML document and you use Simple Transformations to create an identical XML document.You can use the program SPROX_STYLESHEET_TEST for problems with proxies in Web services. This type of problem belongs to the component BC-DWB-PRX and you must forward the problem to this component.XML processing may terminate with a core dump and you cannot find out why. The following procedure should solve this problem in most cases.The customer must always install the most recent kernel. In most cases, you cannot perform an error analysis on an lower kernel level and the most recent kernel normally solves the problem.The libraries for XML processing are integrated dynamically. A version inconsistency between the kernel and the libraries may cause terminations that cannot be explained. The explanation is provided in the log file dev_disp because the system checks the versions when it starts. Note that if the customer has set the profile parameter rdisp/version_check to “off”, the system starts even if a version inconsistency exists. In customer systems, the profile parameter must always be set to “on” to ensure that the system does not start if the versions are inconsistent.

SAP internal documentation about XML

The XML Wiki page from the IMS Development Support Team contains a large amount of information, presentations, and documentation about XML processing.
http://imsabap:1080/abapwiki/AbapXml

iXML
Basis information system:https://bis.wdf.sap.corp/twiki/bin/view/Sapinternal/IXMLLibraryhttps://bis.wdf.sap.corp/twiki/bin/view/Sapinternal/SAPIXMLLibrary

SAP XSLT processor
Basis information system:https://bis.wdf.sap.corp/twiki/bin/view/Sapinternal/SAPXSLTProcessorSAP XSLT processor reference:https://bis.wdf.sap.corp/twiki/pub/Sapinternal/XSLTProcessor/xtc_ref_2_0.html

ABAP Simple Transformations
Basis information system:https://bis.wdf.sap.corp/twiki/bin/view/Sapinternal/AbapXMLSimplTransf

Here is a simple example of a solution for typical problems:

Using the iXML library to create the CDATA section:
DATA:
ixml TYPE REF TO if_ixml,
document TYPE REF TO if_ixml_document,
parent TYPE REF TO if_ixml_node,
element TYPE REF TO if_ixml_element,
cdata TYPE REF TO if_ixml_cdata_section.
* create iXML instance
ixml = cl_ixml=>create( ).
* create iXML document
document = ixml->create_document( ).
* create a node in document
element = document->create_element( name = ‘RootNode’ ).
* append node to document
document->append_child( new_child = element ).
parent = element.
element = document->create_element( name = ‘ChildNode’ ).
parent->append_child( new_child = element ). parent = element.
element = document->create_element( name = ‘SomeOtherTag’ ).
* set attribute in node
element->set_attribute( name = ‘SomeValue’ value = ‘4711′ ).
* create a CDATA section
cdata = document->create_cdata_section( `I0u2TRx6NqlX00002X56um` ).
element = document->create_element( name = ‘Example’ ).
element->append_child( new_child = cdata ).
parent->append_child( new_child = element ). * display document
CALL FUNCTION ‘SDIXML_DOM_TO_SCREEN’
EXPORTING
document = document
title = ‘order’.
Using a transformation to create XML in a specific encoding (for example, ISO-8859-1):
DATA: xmlout TYPE xstring.
DATA: ixml TYPE REF TO if_ixml,
streamfactory TYPE REF TO if_ixml_stream_factory,
encoding TYPE REF TO if_ixml_encoding,
ixml_ostream TYPE REF TO if_ixml_ostream.
* get iXML instance
ixml = cl_ixml=>create( ).
* create a streamfactory
streamfactory = ixml->create_stream_factory( ).
* create a out-stream
ixml_ostream = streamfactory->create_ostream_xstring( xmlout ).
* create an encoding object
encoding = ixml->create_encoding(
character_set = ‘ISO-8859-1′ byte_order = 0 ).
* assign encoding object to out-stream
ixml_ostream->set_encoding( encoding = encoding ).
* call transformation using the out-stream
call transformation z_simple_tt
source root = space
result xml ixml_ostream.
Using iXML to create XML in an internal table and setting a specific encoding for it (for example, UTF-8):
DATA: ixml TYPE REF TO if_ixml,
streamfactory TYPE REF TO if_ixml_stream_factory,
encoding TYPE REF TO if_ixml_encoding,
document TYPE REF TO if_ixml_document,
element TYPE REF TO if_ixml_element,
ixml_ostream TYPE REF TO if_ixml_ostream.
DATA: xml_table TYPE STANDARD TABLE OF char72.
ixml = cl_ixml=>create( ).
streamfactory = ixml->create_stream_factory( ).
document = ixml->create_document( ).
encoding = ixml->create_encoding( character_set = ‘UTF-8′
byte_order = 0 ).
document->set_encoding( encoding = encoding ).
element = document->create_element( name = ‘order’ ).
element->set_attribute( name = ‘number’ value = ‘4711′ ).
document->append_child( new_child = element ).
ixml_ostream = streamfactory->create_ostream_itable( xml_table ).
document->render( ostream = ixml_ostream ).
Creating a very large XML file that does not fit in the main memory; therefore, only a small part is kept in the DOM of iXML:
REPORT zixmldivide.
PARAMETERS: workfile TYPE string DEFAULT ‘iXML_work.xml’.
DATA: ixml TYPE REF TO if_ixml,
document TYPE REF TO if_ixml_document,
streamfactory TYPE REF TO if_ixml_stream_factory,
stream TYPE REF TO if_ixml_ostream,
parent TYPE REF TO if_ixml_node,
element TYPE REF TO if_ixml_element,
encoding TYPE REF TO if_ixml_encoding,
node TYPE REF TO if_ixml_node,
string TYPE string.
* create ixml instance and output stream
ixml = cl_ixml=>create( ).
streamfactory = ixml->create_stream_factory( ).
stream = streamfactory->create_ostream_uri( system_id = workfile ).
* create an empty document to start with
document = ixml->create_document( ).
* render the xml header
document->render( ostream = stream recursive = ‘X’ ).
* well-formed xml requires a root node
stream->write_string( ‘‘ ).
* create some xml fragments
DO 5 TIMES.
string = sy-index.
CONDENSE string NO-GAPS.
element = document->create_element( name = ‘Parent’ ).
document->append_child( new_child = element ).
parent = element.
element = document->create_element( name = ‘Child’ ).
parent->append_child( new_child = element ).
element->set_attribute( name = ‘SomeValue’ value = string ).
parent->append_child( new_child = element ).
* get the document’s first child and render it
node = document->get_first_child( ).
node->render( ostream = stream recursive = ‘X’ ).
* remove all nodes from the document so that the DOM stays confined
document->remove_node( ).
ENDDO.
* close the root node
stream->write_string( ‘
‘ ).
* close the output stream
stream->close( ).

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Leave a Comment