[代码]比较XML文件差异[cl_proxy_ui_utils=>show_xml_diff]详解编程语言

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

[代码]比较XML文件差异[cl_proxy_ui_utils=>show_xml_diff]详解编程语言

代码:

其中可以通过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:/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.

显示结果:

[代码]比较XML文件差异[cl_proxy_ui_utils=>show_xml_diff]详解编程语言

以上。

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19245.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论