sapdev logo background
sapdev logo sapdev logo
Comments

SAP ABAP IXML LIB PARSE ERROR documentation, setup help and example usage



Return to SAP documentation index


ARTICLE

iXML Library - Troubleshooting After Parsing
If a parser detects errors in the XML data while it is parsing, its method NUM_ERRORS returns the number of errors. These can be analyzed using the objects created as follows:
DATA(error) = parser- get_error( index = ... ) .
The static type of the reference variable error is then the interface IF_IXML_PARSER_ERROR . The number of the error can be passed to the parameter index . Counting begins at zero. If index has any other values, error
remains initial.

Example
The parsed XML data contains tags that are not closed correctly, which means that parsing is canceled after the first incorrect tag. The parser corrects the first closing tag but does not write any further data to DOM . The method handle_errors reads the errors.
DATA(ixml) = cl_ixml=>create( ).
DATA(stream_factory) = ixml->create_stream_factory( ).
DATA(istream) = stream_factory->create_istream_string(
`<(><<)>text1>aaa<(><<)>/text><(><<)>text2>bbb<(><<)>/text>` ).
DATA(document) = ixml->create_document( ).
DATA(parser) = ixml->create_parser(
stream_factory = stream_factory
istream = istream
document = document ).

IF parser->parse( ) <(><<)>> ixml_mr_parser_ok.
handle_errors( ).
RETURN.
ENDIF.

...

METHOD handle_errors.
DO parser->num_errors( ) TIMES.
DATA(error) = parser->get_error( index = sy-index - 1 ).
DATA(line) = error->get_line( ).
DATA(column) = error->get_column( ).
DATA(reason) = error->get_reason( ).
...
ENDDO.
ENDMETHOD.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




ABAP_IXML_LIB_PARSE_DOM
ABAP_IXML_LIB_PARSE_EVENT




comments powered by Disqus