读取XML文件方法,其实也不难,可以参考以下的程序:
BCCIIXMLT1
BCCIIXMLT2
BCCIIXMLT3
可以拷贝相关的程序代码,如果想把它的内容读出来给内表,可以把其中的一段代码:
FORM PRINT_NODE USING VALUE(PNODE) TYPE REF TO IF_IXML_NODE.
...
CASE pnode->get_type( ).
WHEN if_ixml_node=>co_node_element.
string = pnode->get_name( ).
WRITE: AT /indent '<', string, '> '. "#EC NOTEXT
WHEN if_ixml_node=>co_node_text.
ptext ?= pnode->query_interface( ixml_iid_text ).
IF ptext->ws_only( ) IS INITIAL.
string = pnode->get_value( ).
WRITE: AT /indent string.
ENDIF.
ENDCASE.
...
ENDFORM.
如果将数据存到哪个内表,只要把调用以下的FORM,数据就会自动写入内表,修改成以下代码:
...
DATA:COL_NUM TYPE I VALUE '1',
...
FORM PRINT_NODE TABLES P_IT_TAB
USING VALUE(PNODE) TYPE REF TO IF_IXML_NODE.
...
FIELD-SYMBOLS <FRM_FIELD>.
CASE PNODE->GET_TYPE( ).
WHEN IF_IXML_NODE=>CO_NODE_ELEMENT. "字段抬头
STRING = PNODE->GET_NAME( ).
"WRITE: AT /indent '<', string, '> '. "#EC NOTEXT
WHEN IF_IXML_NODE=>CO_NODE_TEXT. "字段内容
PTEXT ?= PNODE->QUERY_INTERFACE( IXML_IID_TEXT ).
IF PTEXT->WS_ONLY( ) IS INITIAL.
STRING = PNODE->GET_VALUE( ).
"WRITE: AT /indent string.
ASSIGN COMPONENT COL_NUM OF STRUCTURE P_IT_TAB TO <FRM_FIELD>.
IF SY-SUBRC NE 0.
APPEND P_IT_TAB.
COL_NUM = 1.
ASSIGN COMPONENT COL_NUM OF STRUCTURE P_IT_TAB TO <FRM_FIELD>.
ENDIF.
<FRM_FIELD> = STRING.
ADD 1 TO COL_NUM.
ENDIF.
ENDCASE.
...
ENDFORM.