Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

DOCTYPE Declaration in XML when Transformation

anuradha_wijesinghe
Participant
0 Kudos

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
    exporting
      input = g_xml_string_xstr "(xstring variable with xml)
    receiving
      conv  = lr_conv.

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


Thanks,
Anuradha.
1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

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 http://stackoverflow.com/questions/3387127/set-html5-doctype-with-xslt
  • 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="/">
7 REPLIES 7

anuradha_wijesinghe
Participant
0 Kudos

Can anyone help me please ?

anuradha_wijesinghe
Participant
0 Kudos

Can anyone help me please ?

Sandra_Rossi
Active Contributor
0 Kudos

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 http://stackoverflow.com/questions/3387127/set-html5-doctype-with-xslt
  • 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="/">

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

0 Kudos

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.

0 Kudos

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">'.