Skip to Content

DOCTYPE Declaration in XML when Transformation

Feb 17, 2017 at 04:38 AM


avatar image

Hi Experts,

This is regarding XML generating from ABAP. I'm Trying to convert the Outbound Delivery ( Advice Note ) to a XML file. For that I'm using STRANS Transaction and to create my XML format using a my Defined structure from SE11 (ZSSDPACK_XML)

Then I'm using bellow code segment to generate this XML to utf-8 format. For this I want to add this line to XML.

<!DOCTYPE SdDataSlice SYSTEM "m2Data_Partner.dtd">

So anyone can guide me how can I add this line to the generated XML.

  refresh it_xml.
  call transformation zsd_packing_xml
  source sddataslice = it_final
  result xml g_xml_string_xstr.

  data lr_conv type ref to cl_abap_conv_in_ce.

  call method cl_abap_conv_in_ce=>create
      input = g_xml_string_xstr "(xstring variable with xml)
      conv  = lr_conv.

  call method lr_conv->read
      data = g_xml_string.
  "(string variable with xml encoding utf-8)
  append g_xml_string to it_xml.

structure.jpg (138.6 kB)
strans.jpg (246.1 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Sandra Rossi Feb 18, 2017 at 02:46 PM

I see these solutions (my system's ABAP version is 7.31):

  • If you use a Simple Transformation (<tt:...>), then I couldn't succeed using the transformation itself, nor with sXML (both seem to be able to work only on classic XML element nodes). So I guess the only way is to insert the DTD (<!DOCTYPE...>) to the string after the transformation (using a classic ABAP string manipulation).
  • If you use a XSLT (<xsl:...>), then I could only do it via the transformation and using CALL TRANSFORMATION ... RESULT XML string (it didn't work with RESULT XML sXMLwriter) using the solution mentioned in
  • Solution 1, using XSLT + xsl:text :

<xsl:template match="/">
  <xsl:text disable-output-escaping="yes"><!DOCTYPE SdDataSlice SYSTEM "m2Data_Partner.dtd">;</xsl:text>...
  • Solution 2, using XSLT + xsl:output : if your transformation generates root element "SdDataSlice", then you may also use <xsl:output doctype-system"m2Data_Partner.dtd"/> (note: <xsl:output type="SdDataSlice" is useless because it's always superseded with the target root element):
  • <xsl:output doctype-system="m2Data_Partner.dtd"/>
    <xsl:template match="/">
Show 4 Share
10 |10000 characters needed characters left characters exceeded

Note: instead of basic ABAP string manipulation, I guess it's possible to do it using iXML (class CL_IXML and so on)


Thanks for the Reply. But I'm still having a doubt about this since I'm not much experienced XML, and i have not use XSLT, can u simplify this please.

DATA(doctype) = '<!DOCTYPE SdDataSlice SYSTEM "m2Data_Partner.dtd">'.

" insert the !DOCTYPE right before the root element (i.e. first < which is not <?)
REPLACE REGEX '(?!<\?)(?=<)' IN g_xml_string WITH doctype.

Thank you very much. I replace the string after call transformation.

replace all occurrences of '<?xml version="1.0" encoding="utf-8"?>' in g_xml_string with '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE SdDataSlice SYSTEM "m2Data_Partner.dtd">'.
Anuradha Wijesinghe Feb 18, 2017 at 09:51 AM

Can anyone help me please ?

10 |10000 characters needed characters left characters exceeded
Anuradha Wijesinghe Feb 18, 2017 at 09:51 AM

Can anyone help me please ?

10 |10000 characters needed characters left characters exceeded