ABAP顾问
分类:
2009-07-06 20:37:41
REPORT z_barry_xml_up NO STANDARD PAGE HEADING.
TYPE-POOLS: ixml.
DATA: pixml TYPE REF TO if_ixml,
pdocument TYPE REF TO if_ixml_document,
pstreamfactory TYPE REF TO if_ixml_stream_factory,
pistream TYPE REF TO if_ixml_istream,
pparser TYPE REF TO if_ixml_parser,
pnode TYPE REF TO if_ixml_node,
string TYPE string,
count TYPE i,
index TYPE i,
totalsize TYPE i .
TYPES: BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
DATA: xml_table TYPE TABLE OF xml_line.
START-OF-SELECTION.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'c:\46c.xml'
filetype = 'BIN'
IMPORTING
filelength = totalsize
TABLES
data_tab = xml_table
EXCEPTIONS
OTHERS = 11.
IF sy-subrc <> 0.
EXIT.
ENDIF.
pixml = cl_ixml=>create( ).
pdocument = pixml->create_document( ).
pstreamfactory = pixml->create_stream_factory( ).
pistream = pstreamfactory->create_istream_itable( table = xml_table
size = totalsize ).
pparser = pixml->create_parser( stream_factory = pstreamfactory
istream = pistream
document = pdocument ).
IF pparser->parse( ) NE 0.
IF pparser->num_errors( ) NE 0.
count = pparser->num_errors( ).
WRITE: count, ' parse errors have occured:'.
DATA: pparseerror TYPE REF TO if_ixml_parse_error,
i TYPE i.
index = 0.
WHILE index < count.
pparseerror = pparser->get_error( index = index ).
i = pparseerror->get_line( ).
WRITE: 'line: ', i.
i = pparseerror->get_column( ).
WRITE: 'column: ', i.
string = pparseerror->get_reason( ).
WRITE: string.
index = index + 1.
ENDWHILE.
ENDIF.
ENDIF.
CALL METHOD pistream->close( ).
CLEAR pistream.
pnode = pdocument.
PERFORM print_node USING pnode.