SAP类 cl_proxy_ui_utils中提供了一个方法show_xml_diff,可以比较两个XML文件的差异点,并以不同颜色显示两个xml的差异之处。
代码:
其中可以通过SCMS_BINARY_TO_XSTRING,将xml转换成xstring,实际上最后比较的就是这个xstring。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
REPORT ztest_compare_xml. DATA: lv_original TYPE xstring, lv_changed TYPE xstring. * get xml PERFORM frm_get_file_binary USING 'C:\temp\1.xml' CHANGING lv_original. PERFORM frm_get_file_binary USING 'C:\temp\2.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. |
显示结果:
以上。
发表评论