PHPXMLExpat parser. There are two basic types of XML parser: tree-based parser, which converts XML documents into a tree structure. It analyzes the entire document and provides APIs to access tree elements. There are two basic types of XML parser:
Tree-based parser: this parser converts an XML document into a tree structure. It analyzes the entire document and provides APIs to access tree elements, such as the Document Object Model (DOM ).
Event-based parser: treats XML documents as a series of events. When a specific event occurs, the parser calls a function to process it.
The Expat parser is an event-based parser.
The XML Expat parser is a core component of PHP. You can use these functions 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 at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); }//Free the XML parserxml_parser_free($parser);?>
Parser XML parser type: tree-based parser: this parser converts XML documents into tree structures. It analyzes the entire document and provides APIs to access the elements of the tree...