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



PHP : Function Reference : XML Parser Functions : xml_get_current_column_number

xml_get_current_column_number

Get current column number for an XML parser (PHP 4, PHP 5)
int xml_get_current_column_number ( resource parser )

Examples ( Source code ) » xml_get_current_column_number

<?php
class Simple_Parser
{
    var 
$parser;
    var 
$error_code;
    var 
$error_string;
    var 
$current_line;
    var 
$current_column;
    var 
$data = array();
    var 
$datas = array();
    
    function 
parse($data)
    {
        
$this->parser xml_parser_create('UTF-8');
        
xml_set_object($this->parser$this);
        
xml_parser_set_option($this->parserXML_OPTION_SKIP_WHITE1);
        
xml_set_element_handler($this->parser'tag_open''tag_close');
        
xml_set_character_data_handler($this->parser'cdata');
        if (!
xml_parse($this->parser$data))
        {
            
$this->data = array();
            
$this->error_code xml_get_error_code($this->parser);
            
$this->error_string xml_error_string($this->error_code);
            
$this->current_line xml_get_current_line_number($this->parser);
            
$this->current_column xml_get_current_column_number($this->parser);
        }
        else
        {
            
$this->data $this->data['child'];
        }
        
xml_parser_free($this->parser);
    }
    function 
tag_open($parser$tag$attribs)
    {
        
$this->data['child'][$tag][] = array('data' => '''attribs' => $attribs'child' => array());
        
$this->datas[] =& $this->data;
        
$this->data =& $this->data['child'][$tag][count($this->data['child'][$tag])-1];
    }
    function 
cdata($parser$cdata)
    {
           
$this->data['data'] .= $cdata;
    }
    function 
tag_close($parser$tag)
    {
           
$this->data =& $this->datas[count($this->datas)-1];
           
array_pop($this->datas);
    }
}
$xml_parser = new Simple_Parser;
$xml_parser->parse('<foo><bar>test</bar></foo>');
?>

Code Examples / Notes » xml_get_current_column_number

shaun

Column numbers apparently start at 0. So you may want to add 1.

javajohn

"Column number" refers to the current character position within the current line of the XML document.

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