• [代码]比较XML文件差异[cl_proxy_ui_utils=>show_xml_diff]


    SAP类 cl_proxy_ui_utils中提供了一个方法show_xml_diff,可以比较两个XML文件的差异点,并以不同颜色显示两个xml的差异之处。

    代码:

    其中可以通过SCMS_BINARY_TO_XSTRING,将xml转换成xstring,实际上最后比较的就是这个xstring

    REPORT ztest_compare_xml.
    
    DATA: lv_original TYPE xstring,
          lv_changed  TYPE xstring.
    
    * get xml
    PERFORM frm_get_file_binary USING 'C:	emp1.xml'
                                CHANGING lv_original.
    PERFORM frm_get_file_binary USING 'C:	emp2.xml'
                                CHANGING lv_changed .
    
    * compare xml
    CALL METHOD cl_proxy_ui_utils=>show_xml_diff
      EXPORTING
        doc1 = lv_original
        doc2 = lv_changed.
    *&---------------------------------------------------------------------*
    *&      Form  FRM_GET_FILE_BINARY
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_0014   text
    *      <--P_LV_ORIGINAL  text
    *----------------------------------------------------------------------*
    FORM frm_get_file_binary  USING    i_path
                              CHANGING c_xml.
    
      CONSTANTS c_linelen TYPE i VALUE 255.
      DATA: wa_data(c_linelen) TYPE x,
            it_data            LIKE TABLE OF wa_data,
            converter          TYPE REF TO cl_abap_conv_in_ce,
            lv_xstring         TYPE xstring,
            lv_length          TYPE i.
    
      CALL METHOD cl_gui_frontend_services=>gui_upload
        EXPORTING
          filename                = i_path
          filetype                = 'BIN'
        IMPORTING
          filelength              = lv_length
        CHANGING
          data_tab                = it_data
        EXCEPTIONS
          file_open_error         = 1
          file_read_error         = 2
          no_batch                = 3
          gui_refuse_filetransfer = 4
          invalid_type            = 5
          no_authority            = 6
          unknown_error           = 7
          bad_data_format         = 8
          header_not_allowed      = 9
          separator_not_allowed   = 10
          header_too_long         = 11
          unknown_dp_error        = 12
          access_denied           = 13
          dp_out_of_memory        = 14
          disk_full               = 15
          dp_timeout              = 16
          not_supported_by_gui    = 17
          error_no_gui            = 18
          OTHERS                  = 19.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    
      CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
        EXPORTING
          input_length = lv_length
        IMPORTING
          buffer       = lv_xstring
        TABLES
          binary_tab   = it_data
        EXCEPTIONS
          failed       = 1
          OTHERS       = 2.
      IF sy-subrc  <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    
      c_xml = lv_xstring.
    
    ENDFORM.

    显示结果:

    以上。

  • 相关阅读:
    【BZOJ5286】[HNOI2018]转盘(线段树)
    【BZOJ2003】[HNOI2010]矩阵(搜索)
    【BZOJ2000】[HNOI2000]取石头游戏(贪心,博弈论)
    【BZOJ1998】[HNOI2010]物品调度(并查集,模拟)
    【BZOJ2001】[HNOI2010]城市建设(CDQ分治,线段树分治)
    【BZOJ1925】[SDOI2010]地精部落(动态规划)
    【BZOJ1856】[SCOI2010]字符串(组合数学)
    【BZOJ1826】[JSOI2010]缓存交换(贪心)
    【BZOJ1823】[JSOI2010]满汉全席(2-sat)
    【BZOJ1822】[JSOI2010]冷冻波(二分,网络流)
  • 原文地址:https://www.cnblogs.com/datie/p/11434611.html
Copyright © 2020-2023  润新知