Current Location: Home> Function Categories> xml_parser_create

xml_parser_create

Create an XML parser
Name:xml_parser_create
Category:XML parser
Programming Language:php
One-line Description:Create an XML parser.

Definition and usage

The xml_parser_create() function is used to create an XML parser.

Tip: To release the XML parser, use xml_parser_free() function.

Tip: To create an XML parser that supports namespaces, use xml_parser_create_ns() function instead.

Example

Create an XML parser and parse the XML document ( note.xml ):

 <?php
// Create XML parser
$parser = xml_parser_create ( ) ;

function char ( $parser , $data ) {
  echo $data ;
}

xml_set_character_data_handler ( $parser , "char" ) ;
$fp = fopen ( "note.xml" , "r" ) ;

while ( $data = fread ( $fp , 4096 ) ) {
  // parse XML data
  xml_parse ( $parser , $data , feof ( $fp ) ) or
  die ( sprintf ( "XML error: %s on line %d" ,
  xml_error_string ( xml_get_error_code ( $parser ) ) ,
  xml_get_current_line_number ( $parser ) ) ) ;
}

xml_parser_free ( $parser ) ;
fclose ( $fp ) ;
?>

Run the instance

grammar

 xml_parser_create ( encoding )
parameter describe
encoding

Optional. Specify the character encoding for input/output in PHP 4. Starting with PHP 5, only the character encoding of the output is specified.

In PHP 5.0.0 and 5.0.1, the default output character set is ISO-8859-1.

Starting with PHP 5.0.2, the default output character set is UTF-8.

Similar Functions
Popular Articles