xml_set_object
オブジェクトにXMLパーサーを使用します
xml_set_object()
関数は、オブジェクトにxmlパーサーを使用できます。
在对象中使用XML解析器:
<?php クラスxmlparser { プライベート$パーサー; function __construct ( ) { $ this- > parser = xml_parser_create ( ) ; xml_set_object ( $ this- > parser 、 $ this ) ; xml_set_element_handler ( $ this- > parser 、 "start_tag" 、 "end_tag" ) ; xml_set_character_data_handler ( $ this- > parser 、 "cdata" ) ; } function __destruct ( ) { xml_parser_free ( $ this- > parser ) ; unset ( $ this- > parser ) ; } function parse ( $ data ) { xml_parse ( $ this- > parser 、 $ data ) ; } function start_tag ( $ parser 、 $ tag 、 $属性) { var_dump ( $ tag 、 $属性) ; } function cdata ( $ parser 、 $ cdata ) { var_dump ( $ cdata ) ; } function end_tag ( $ parser 、 $ tag ) { var_dump ( $ tag ) ; } } $ xml_parser = new xmlparser ( ) ; $ xml_parser- > parse ( "<p id = 'test'> hello world!</p>" ) ; ?>
运行实例
xml_set_object (パーサー、オブジェクト)
パラメーター | 説明する |
---|---|
パーサー | 必須。使用するXMLパーサーを指定します。 |
物体 | 必須。 XMLパーサーを使用するオブジェクトを指定します。 |