Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : XML Parser Functions : xml_get_current_line_number

xml_get_current_line_number

Get current line number for an XML parser (PHP 4, PHP 5)
int xml_get_current_line_number ( resource parser )

Gets the current line number for the given XML parser.

Parameters

parser

A reference to the XML parser to get line number from.

Return Values

This function returns FALSE if parser does not refer to a valid parser, or else it returns which line the parser is currently at in its data buffer.

Examples ( Source code ) xml_get_current_line_number

<?php
$file 
"data.xml";
$depth = array();

function 
startElement($parser$name$attrs)
{
   global 
$depth;
   for (
$i 0$i $depth[$parser]; $i++) {
       echo 
"  ";
   }
   echo 
"$name\n";
   
$depth[$parser]++;
}

function 
endElement($parser$name)
{
   global 
$depth;
   
$depth[$parser]--;
}

$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
if (!(
$fp fopen($file"r"))) {
   die(
"could not open XML input");
}

while (
$data fread($fp4096)) {
   if (!
xml_parse($xml_parser$datafeof($fp))) {
       die(
sprintf("XML error: %s at line %d",
                   
xml_error_string(xml_get_error_code($xml_parser)),
                   
xml_get_current_line_number($xml_parser)));
   }
}
xml_parser_free($xml_parser);
?>

Related Examples ( Source code ) » xml_get_current_line_number





Change Language


Follow Navioo On Twitter
utf8_decode
utf8_encode
xml_error_string
xml_get_current_byte_index
xml_get_current_column_number
xml_get_current_line_number
xml_get_error_code
xml_parse_into_struct
xml_parse
xml_parser_create_ns
xml_parser_create
xml_parser_free
xml_parser_get_option
xml_parser_set_option
xml_set_character_data_handler
xml_set_default_handler
xml_set_element_handler
xml_set_end_namespace_decl_handler
xml_set_external_entity_ref_handler
xml_set_notation_decl_handler
xml_set_object
xml_set_processing_instruction_handler
xml_set_start_namespace_decl_handler
xml_set_unparsed_entity_decl_handler
eXTReMe Tracker