PHPXMLExpat parser _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.