XML Error Handling

One final alteration you'll probably want to make to the parse.php script is to take into account error handling. Because part of the purpose of parsing XML files is to check that they are well-formed (free of errors), you'll want to devise a system for making note of any issues. There are two primary XML error-handling functions to use.

xml_get_error_code($parser); 

xml_error_string($error_code);

The first function takes the $parser reference as its argument and will report the error code associated with the parser, when an error occurs. The second function can take this code and turn it into a string version of the problem.

Almost every resource I've seen discussing PHP and Expat uses some variation on the following for ...

Get PHP Advanced for the World Wide Web: Visual QuickPro Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.