文件名称:生成XML文件ABAP程序
文件大小:6KB
文件格式:TXT
更新时间:2013-07-29 08:50:33
生成XML文件
生成XML文件ABAP程序 REPORT zams_xml_dom_create . TYPE-POOLS: ixml. CLASS cl_ixml DEFINITION LOAD. TYPES: BEGIN OF xml_line, data(256) TYPE x, END OF xml_line. DATA: l_ixml TYPE REF TO if_ixml, l_streamfactory TYPE REF TO if_ixml_stream_factory, l_ostream TYPE REF TO if_ixml_ostream, l_renderer TYPE REF TO if_ixml_renderer, l_document TYPE REF TO if_ixml_document. DATA:l_element_ArchiveBatch TYPE REF TO if_ixml_element, l_element_BatchNumber TYPE REF TO if_ixml_element, l_element_TotalFiles TYPE REF TO if_ixml_element, l_element_TotalVolumes TYPE REF TO if_ixml_element, l_element_TotalPieces TYPE REF TO if_ixml_element, l_element_Entries TYPE REF TO if_ixml_element, l_element_Entry TYPE REF TO if_ixml_element, l_element_RecordsCombiningType TYPE REF TO if_ixml_element, l_element_FilePath TYPE REF TO if_ixml_element, l_element_SourceFileName TYPE REF TO if_ixml_element, l_element_ClassificationCode TYPE REF TO if_ixml_element, l_element_ElectronicRecordCode TYPE REF TO if_ixml_element, l_value TYPE string, l_name type string. DATA: l_xml_table TYPE TABLE OF xml_line, l_xml_size TYPE i, l_rc TYPE i. START-OF-SELECTION. *Creating a ixml factory l_ixml = cl_ixml=>create( ). *Creating the dom object model l_document = l_ixml->create_document( ). *Fill root node with value ArchiveBatch l_element_ArchiveBatch = l_document->create_simple_element( name = 'ArchiveBatch' parent = l_document ). * clear l_value. * l_value = '"http://www.w3.org/2001/XMLSchema-instance"'. * l_rc = l_element_ArchiveBatch->set_attribute( name = 'xmlns: *xsi' * value = l_value ). * * clear l_value. * concatenate '"D:\dev\vs\projects\AMS\DotNet\Sinopec.Ams.' * 'Integration\bin\Debug\config\AmsIntegration.xsd"' * into l_value. * l_name = 'xsi:noNamespaceSchemaLocation'. * l_rc = l_element_ArchiveBatch->set_attribute( name = l_name *value = l_value ). *BatchNumber l_element_BatchNumber = l_document->create_simple_element( name = 'BatchNumber' value = '20100609001' parent = l_element_ArchiveBatch ). *TotalFiles l_element_TotalFiles = l_document->create_simple_element( name = 'TotalFiles' value = '5' parent = l_element_ArchiveBatch ). *TotalVolumes l_element_TotalVolumes = l_document->create_simple_element( name = 'TotalVolumes' value = '3' parent = l_element_ArchiveBatch ). *TotalPieces l_element_TotalPieces = l_document->create_simple_element( name = 'TotalPieces' value = '5' parent = l_element_ArchiveBatch ). *Entries l_element_Entries = l_document->create_simple_element( name = 'Entries' parent = l_element_ArchiveBatch ). *Entry1 l_element_Entry = l_document->create_simple_element( name = 'Entry' parent = l_element_Entries ). *Entry1下面的子项 *RecordsCombiningType l_element_RecordsCombiningType = l_document->create_simple_element( name = 'RecordsCombiningType' value = 'Volume' parent = l_element_Entry ). *FilePath l_element_FilePath = l_document->create_simple_element( name = 'FilePath' value = '全宗001/目录001/案卷001/档案一.docx' parent = l_element_Entry ). *SourceFileName l_element_SourceFileName = l_document->create_simple_element( name = 'SourceFileName' value = '档案一' parent = l_element_Entry ). *ClassificationCode l_element_ClassificationCode = l_document->create_simple_element( name = 'ClassificationCode' value = 'wenshu' parent = l_element_Entry ). *ElectronicRecordCode l_element_ElectronicRecordCode = l_document->create_simple_element( name = 'ElectronicRecordCode' value = 'BJSH-001' parent = l_element_Entry ). *Entry1 * Creating a stream factory l_streamfactory = l_ixml->create_stream_factory( ). * Connect internal XML table to stream factory l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ). * Rendering the document l_renderer = l_ixml->create_renderer( ostream = l_ostream document = l_document ). l_rc = l_renderer->render( ). * Saving the XML document 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\metas.xml' filetype = 'BIN' CHANGING data_tab = l_xml_table EXCEPTIONS OTHERS = 24. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.