There are two basic types of XML parsers:
Tree-based parser: This parser transforms an XML document into a tree structure. It parses the entire document and provides an API to access the elements of the tree, such as the Document Object Model (DOM).
Event-based parser: treats an XML document as a series of events. When a specific event occurs, the parser invokes the function to process it.
The Expat parser is an event-based parser.
The XML Expat parser is part of the PHP core. These functions can be used without installation.
XML file:
George
John
Reminder
Don ' t forget the meeting!
Initialize the XML parser:
"; Break Case ' to ': Echo ' to: '; Break Case ' from ': Echo ' from: '; Break Case "HEADING": Echo "HEADING:"; Break Case "BODY": Echo "Message:"; }//function to use at the end of an elementfunction stop ($parser, $element _name) {echo "
"; }//function to use when finding character datafunction char ($parser, $data) {echo $data; }//specify element Handlerxml_set_element_handler ($parser, "Start", "Stop"),//specify data handlerxml_set_character_ Data_handler ($parser, "char"),//open XML File$fp=fopen ("Test.xml", "R"),//read Datawhile ($data =fread ($fp, 4096)) {XML _parse ($parser, $data, feof ($fp)) or Die (sprintf ("XML Error:%s @ line%d", Xml_error_string (Xml_get_error_code ($parse R)), Xml_get_current_line_number ($parser))); }//free the XML parserxml_parser_free ($parser);? >
http://www.bkjia.com/PHPjc/755779.html www.bkjia.com true http://www.bkjia.com/PHPjc/755779.html techarticle There are two basic types of XML parsers: Tree-based parsers: This parser transforms an XML document into a tree structure. It parses the entire document and provides an API to access the elements of the tree species ...