Case Study: Reading an XML Document 12.5
RAISE EXCEPTION TYPE cx_ixml_parse_error
EXPORTING
textid -
cx_ixml_parse_error->cx_ixml_parse_error
code - lv_error_code
reason - lv_reason
line - lv_line
column - lv_column.
ENOIF.
ENDMETHOD.
ENOCLASS.
Listing 12.10 Parsing an XML-8ased Reading List File
Listing 12.10 again uses the standard class CL_GUI_FRONTEND_SERVICES to read the
XML file into an internal table variable called I t_xml. Next, an input stream object
is created that will be used to feed the raw input from the XML file into the XML
parser. After that, a reference to an XML parser instance is obtained that imple-
ments the IF_IXML_PARSER interface. Finally, the PARSE method defined in the
IF_IXHL_PARSER interface is used to parse the XML document. This method pro-
duces a return code that indicates whether or not the parser was able to success-
fully parse the document. In the event that there are parsing errors (due to mal-
formed XML content, for instance), you can call the GET_ERROR method to obtain
a reference to an object that implements the I F_IXML_PARSE_ERROR interface. This
object provides various methods that provide details about the error such as the
line number/column where the error occurred, a text-based description of the
error, and so on.
If there are no errors during the parsing process, the generated DOM-based XML
document will be stored in the xml_document instance attribute. For convenience,
the create_from_f
i
le method also looks up the <ReadingList> and <Recommended
Books> elements and stores references to them inside the instance attributes
l ist_node and books_node, respectively. Caching this information makes it easier
to modify the XML document later via public instance methods, and so on.
To verify that the XML document is parsing correctly, a di spl ay method has been
implemented that can be used to display the derived XML document in a browser
window. This display functionality is driven by the standard function module
SDI XML_DOM_TO_SCREEN (see Listing 12.11).
323