When dealing with the manipulation of XML data (e.g. XSLT transformation, ABAP class mapping) we often face the problem to visualize the changed XML data in an easy way. As a consequence we usually need more iterations to adjust our program logic in order to get the required results.
Another challenge is when we receive XML data as xstring input. If errors occur how can we exclude (or confirm) that the XML was erroneous? Example: The input of the eBPP Customer component are base64-encoded DocumentSets. During the processing of these records XML INVOIC-IDocs are generated.
Finally, another trigger to write this blog was a comment to Michal Krawczyk‘s blog (The specified item was not found. requesting for a better output of the XML data.
Class CL_XML_DOCUMENT – The jack-of-all-trades
The following piece of coding shows that as soon as you have created an instance of CL_XML_DOCUMENT you are just 2 simple steps away from displaying XML data received as xstring:
(1) Parse the XML Stream (XString) to DOM
(2) Display document
The XML document is displayed in a HTML viewer. In order to search through the XML simply use CTRL+F.
Irrespective of whether the XML input is provided as file, internal itab, string, or xstring class CL_XML_DOCUMENT provides the appropriate methods for loading (file) or parsing the XML input (not shown; see Appendix: report ZUS_SDN_XML_DISPLAY).
Use Cases for XML Visualization
Currently I have 2 Use Cases in which I apply the versatility of class CL_XML_DOCUMENT:
(1) All ABAP class mapping on SAP-PI have a static TEST method in which I can display the XML before and after the mapping.
(2) eBPP Customer (Troubleshooting): As soon as I execute processing of DocumentSets in Debugging mode I can display the intermediate XML-IDocs in the HTML viewer for visual inspection.
Whenever you need to quickly visualize XML data take advantage of the versatile methods of class CL_XML_DOCUMENT.
Coding of sample report ZUS_SDN_XML_DISPLAY.