Masz klasy:
<?php
class XML {
private $level, $levels;
function __construct( $file ) {
if( !file_exists( $file ) ) {
return;
}
if( ( $fh = @fopen( $file, 'r' ) ) === false ) {
return;
}
$xml = xml_parser_create();
xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 1 );
xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
xml_set_element_handler( $xml, array( $this, 'elementStart' ), array( $this, 'elementEnd' ) );
xml_set_character_data_handler( $xml, array( $this, 'elementContent' ) );
$this->level = 0;
$this->levels = array( $this );
while( ( $data = fread( $fh, 512 ) ) != false ) {
if( !xml_parse( $xml, $data, feof( $fh ) ) ) {
return;
}
}
unset( $this->level );
unset( $this->levels );
xml_parser_free( $xml );
fclose( $fh );
}
function elementStart( $xml, $name, $attrs ) {
$element = new XMLElement( $name, $attrs );
$this->levels[$this->level]->childs[] = $element;
$this->level++;
$this->levels[$this->level] = $element;
}
function elementEnd( $xml, $name ) {
$this->levels[$this->level]->content = trim( $this->levels[$this->level]->content );
$this->level--;
}
function elementContent( $xml, $content ) {
$this->levels[$this->level]->content .= $content;
}
}
class XMLElement {
function __construct( $name, $attrs ) {
$this->name = $name;
$this->content = '';
$this->childs = array();
$this->attrs = array();
foreach( $attrs as $key => $value ) {
$this->attrs[$key] = $value;
}
}
}
?>
Może coś Ci to pomoże.