In this example, the PHP file is read, the XML file is displayed below the content of the PHP file, and the PHP file and SlashDot.xml are in the same folder PHP $ OPEN_TAGS = Array ('story' => "
We will then use // // when you encounter story> tags in the story> tag, we know all temporary variables to be Flush Function endelement ($ Parser, $ Name, $ attrs = ') { Global $ Close_Tags, $ TEMP, $ CURRENT_TAG; IF ($ FORMAT = $ Close_tags [$ Name]) {Switch ($ Name) {CASE ': RETURN_PAGE ($ TEMP); $ TEMP ='; Break; Default: Break;}}} // Transfer to this function data //// Global $ CURRENT_TAG, $ TEMP, $ CACID; Switch ($ current_tag) {CASE 'TITLE': $ TEMP ['Title'] = $ data; $ current_tag = '; break; case' url ': $ TEMP [' URL '] = $ data; $ current_tag ='; Break; Case 'Author': $ TEMP ['Author'] = $ data; $ current_tag = '; default: Break;}}?> php function return_page ) {Global $ TEMP; Echo 'o '. $ TEMP ['
'; Echo 'Author : '. $ TEMP [' Author '].'
'; echo' ---------------- ------------- '; Echo'
';} // Analysis content $ XML_FILE =' SlashDot.xml '; // Define the character set, default is UTF-8 $ TYPE = 'UTF-8'; // the parser $ xml_parser = xml_parser_create ($ type); // set the resolution options xml_parser_set_option ($ xml_parser, XML_OPTION_CASE_FOLDING, true); xml_parser_set_option ($ xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); / / Telling the PHP discovery element to call what function // These functions also handle the properties of the element XML_SET_ELEMENT_HANDLER ($ XML_Parser, 'StartElement "