生成xml文件例子

 

采用Pull生成Xml文件:

    public    static    void    save(List<Person>    persons,    IntputStream    is)    throws    Exception{

        XmlSerializer    serialzer    =    Xml.newSerialzer()    ;

        serialzer.setOutput(is,"UTF-8")    ;

        serialzer.startDocument("UTF-8",true)    ;

        serialzer.startTag(null,"persons")    ;

        for(Person    person    :    persons){

            serialzer.startTag(null,"person")    ;

            serialzer.attribute(null,"id",person.getId().toString())    ;

            serialzer.startTag(null,"name")    ;

            serialzer.text(person.getName())    ;

            serilzer.endTag(null,"name")    ; 

            serialzer.startTag(null,"age")    ;

            serialzer.text(person.getAge())    ;

            serilzer.endTag(null,"age")    ; 

            serialzer.endTag(null,"person")    ;

        }

        serialzer.endTag(null,"persons")    ;

        serialzer.endDocument()    ;

        is.flush()    ;

        is.close()    ;

    }

    生成:

        <?xml version="1" encord="utf-8"?>  

            <out:persons>                       

                <person id="9">             

                    <name>CongHua</name>     

                    <age>20</age>         

                </person>    

            <persons>         

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
生成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.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值