? Php ** nbs...
DomRootObject;} public function parse ($ file) {$ xmlParser = xml_parser_create (); xml_parser_set_option ($ xmlParser, parser, 0); xml_parser_set_option ($ xmlParser, parser, 1 ); xml_parser_set_option ($ xmlParser, parser, 'utf-8'); xml_set_object ($ xmlParser, $ this); xml_set_element_handler ($ xmlParser, "startElement", "endElement"); comment A_handler ($ xmlParser, "characterData"); if (! Xml_parse ($ xmlParser, file_get_contents ($ file) die (sprintf ("XML error: % s at line % d", xml_error_string (xml_get_error_code ($ xmlParser )), xml_get_current_line_number ($ xmlParser); xml_parser_free ($ xmlParser);} private function startElement ($ parser, $ name, $ attrs) {$ this-> currentName = $ name; $ this-> currentAttribute = $ attrs; if ($ this-> currentNO = null) {$ this-> domRootObject = new SimpleDocu MentRoot ($ name); $ this-> currentNO = $ this-> domRootObject;} else {$ this-> currentNO = $ this-> currentNO-> createNode ($ name, $ attrs) ;}} private function endElement ($ parser, $ name) {if ($ this-> currentName ==$ name) {$ tag = $ this-> currentNO-> getSeq (); $ this-> currentNO = $ this-> currentNO-> getPNodeObject (); if ($ this-> currentAttribute! = Null & sizeof ($ this-> currentAttribute)> 0) $ this-> currentNO-> setValue ($ name, array ('value' => $ this-> currentValue, 'attrs' => $ this-> currentAttribute); else $ this-> currentNO-> setValue ($ name, $ this-> currentValue ); $ this-> currentNO-> removeNode ($ tag);} else {$ this-> currentNO = (is_a ($ this-> currentNO, 'simpledocumentroot '))? Null: $ this-> currentNO-> getPNodeObject () ;}} private function characterData ($ parser, $ data) {$ this-> currentValue = iconv ('utf-8 ', 'gb2312', $ data);} function _ destruct () {unset ($ this-> domRootObject); }}?>
Permanent link:
Reprint at will! Include the article address.