XML application in PHP (1)
Source: Aspsky . XML is a set of rules that define semantic tags that divide documents into many parts and identify them. It is also a meta-marking language that defines syntax language for defining other, semantic, structured marking languages related to specific areas. XML is the most popular technology today. PHP also has the function of analyzing the XML document. Here we will discuss the situation of XML applications in PHP. P>
The following is a / "Hello-World /" XML document example:
The elements used in the document of the sub-elements of the parent element of the number of characters in the element data Note: For demonstration, we use php to generate a structure to save the parent element and child elements of the element. Used to generate XML parsing What are the functions of an instance? A function for generating an XML parser instance is XML_Parser_create (). This instance will be used for all functions. This idea is very similar to the connection tag of the MySQL function in PHP. Event-based parsers are usually required to register the callback function before resolving the document - calling when a specific event occurs. Expat no exceptions, it defines the following seven possible events: the beginning and end of the character objects XML parsing function describes the elements xml_set_element_handler () element data xml_set_character_data_handler () to start an external entity xml_set_external_entity_ref_handler character data () external entities appear External unparsed entity xml_set_unparsed_entity_decl_handler () Unresolved external entity appearance processing command XML_SET_PROCESSING_INSTRUCTION_HANDLER () Processing Declaration of XML_SET_NOTATION_DECL_HANDLER () Declaration Default XML_SET_DEFAULT_HANDLER () Other Events without specifying a handler All callback functions must be parsing Examples are the first parameter (there are other parameters). For the final example script of this article, it is important to note that it uses both the element processing function and the character data processing function. The callback process function of the element is registered by XML_SET_ELEMENT_HANDLER (). This function requires three parameters: The name of the callback function of the parser's instance processing start element The name of the callback function of the end element must exist when the XML document begins. They must be defined as the same as the prototypes described in the PHP manual. For example, EXPAT passes three parameters to the process function of the start element. In the script example, it is as defined as follows: Function Start_Element ($ PARSER, $ Name, $ Attrs) $ parser is a parser flag, $ name is the name of the start element, $ attrs is all attributes and values including elements Array. Once the XML document is started, EXPAT will call the start_element () function and pass the parameters in the past. XML's Case Folding options are turned off with an XML_Parser_Set_Option () function to turn the Case Folding option. This option is open by default, so that the element name passed to the processing function is automatically converted to uppercase. But XML is sensitive to uppercase (so case in cases are very important to statistical XML documents). For our example, the CASE Folding option must be turned off.