Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2803

Sap abap development

$
0
0

Hi,

 

Initially what I want is to convert internal table in to a XML document using custom DOM. Now I'm succeeded. but in xml file i'm getting self closed xml tags.  ex: <product/>  instead of  <product> </product>. I Went through most of the solutions and couldn't able to find a proper solution for my case. It would be helpful if any one can address this question.Please help.  

 

Up to now what I did was..

 

TYPE-POOLS: IXML.

   TYPES: BEGIN OF XML_LINE,

            DATA(256) TYPE X,

          END OF XML_LINE.

   DATAL_XML_TABLE       TYPE TABLE OF XML_LINE,

          L_XML_SIZE        TYPE I,

          L_RC              TYPE I,

          L_OSTREAM         TYPE REF TO IF_IXML_OSTREAM.

   DATA: L_IXML TYPE REF TO IF_IXML.

   L_IXML = CL_IXML=>CREATE( ).

 

 

 

This iXML factory can create an empty XML document object named l_document.

   DATAL_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT.

   L_DOCUMENT = L_IXML->CREATE_DOCUMENT( ).

 

*At this point you can add the nodes (elements, attributes) into the document. First you have to declare the root element node.

   DATA: L_ELEMENT_ROOT TYPE REF TO IF_IXML_ELEMENT.

 

   "-------------------------------------------------------------------------------------------- Root Node -----1-------------------------------------

 

*This node we have to give a name and add it (create_simple_node) to the document object l_document, which will be the parent of this node.

   L_ELEMENT_ROOT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT(

              NAME = 'SDDATASLICE'

            PARENT = L_DOCUMENT ).

 

   "-------------------------------------------------------------------------------------------- SD COMPANY HEADER ------------------------------------

 

*Next we can add child nodes to there parent node using the same method of the document object.

   DATA: L_ELEMENT_HEADER TYPE REF TO IF_IXML_ELEMENT.

   L_ELEMENT_HEADER  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'SDcompanyheader'

  PARENT = L_ELEMENT_ROOT  ).


DATA: L_ELEMENT_LEGALNAME TYPE REF TO IF_IXML_ELEMENT.

   L_ELEMENT_LEGALNAME  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'LegalName'

  PARENT = L_ELEMENT_HEADER  ).


and etc.......


at the end ..


DATA: L_STREAMFACTORY   TYPE REF TO IF_IXML_STREAM_FACTORY.

   L_STREAMFACTORY = L_IXML->CREATE_STREAM_FACTORY( ).


  L_OSTREAM = L_STREAMFACTORY->CREATE_OSTREAM_ITABLE( TABLE = L_XML_TABLE ).


*When we have created the output stream we can do the rendering from the document into the stream. The XML data will be stored in the internal table automatically.


   DATA: L_RENDERER        TYPE REF TO IF_IXML_RENDERER.

   L_RENDERER = L_IXML->CREATE_RENDERER( OSTREAM  = L_OSTREAM DOCUMENT = L_DOCUMENT ).

   L_RC = L_RENDERER->RENDER( ).

 

*In the last step we upload the file to the sapgui


   L_XML_SIZE = L_OSTREAM->GET_NUM_WRITTEN_RAW( ).

 

   CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD

     EXPORTING

       BIN_FILESIZE = L_XML_SIZE

       FILENAME     = 'c:/temp/PackingNumber.xml'

       FILETYPE     = 'BIN'

     CHANGING

       DATA_TAB     = L_XML_TABLE

     EXCEPTIONS

       OTHERS       = 24.




As you already know. Xml is already generating with self closed tags for empty fields. what I want is to change self closing tags into <xxxxx> </xxxxx>  format.


xml what i get is something like this..


-<SdPackingSlipLine>

     <PackingSlipLineNumber/>    " <-------------- Self closing tags

     <OrderTypeName/>

     <OrderNumber/>

     <OrderDate/>

     <OrderLineNumber/>

     <Qty/>

-</SdPackingSlipLine>


Please help...


Thanks,

Chamira Dias


Viewing all articles
Browse latest Browse all 2803

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>