PHP and MySQL Web Development - P161: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | 772 Chapter 31 Connecting to Web Services with XML and SOAP After all these parameters are set we call this- parseXML to actually do the parseXML method is shown in Listing . Listing parseXML Method Parsing the XML Returned from a Query Parse the XML into Product object s function parseXML xml_parser xml_parser_create xml_parser_set_option xml_parser XML_OPTION_SKIP_WHITE 1 xml_set_object xml_parser this xml_set_element_handler xml_parser startElementHandler endElementHandler xml_set_character_data_handler xml_parser cdataHandler if fp fopen this- _url r die could not open XML input while data fread fp 4096 if xml_parse xml_parser data feof fp die sprintf XML error s at line d xml_error_string xml_get_error_code xml_parser xml_get_current_line_number xml_parser xml_parser_free xml_parser In this method we are using PHP s XML library which is based on expat. We begin by calling the xml_parser_create function. This creates an instance of the parser and returns a handle to this parser which will need to be passed to other functions. We then need to set up a few things in this parser before we can actually parse the XML document as follows xml_parser_set_option xml_parser XML_OPTION_SKIP_WHITE 1 xml_set_object xml_parser this xml_set_element_handler xml_parser startElementHandler endElementHandler xml_set_character_data_handler xml_parser cdataHandler Solution Overview 773 The first line sets the parser to skip whitespace which will save effort .There are a few other options that can be set with this function but this is the only one relevant here. The next three lines are used to set up callback need to tell the parser what to do when it finds elements and character data inside the XML document. The call to xml_set_object tells the parser that the callback functions will be found inside this the current AmazonResultSet object. If we were just using regular functions rather than class methods we would not need this function call. The .