Tag Archives: XML

xml_set_element_handler()

It set up start and end element handlers

Example
<?php
$xmlparser=xml_parser_create();

function start($xmlparser,$element_name,$element_attrs) {
echo $element_name;
}

function stop($xmlparser,$element_name){
echo “n”;
}

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

xml_set_element_handler($xmlparser,”start”,”stop”);
xml_set_character_data_handler($xmlparser,”char”);
$fp=fopen(“book.xml”,”r”);

while ($data=fread($fp,4096)){
xml_parse($xmlparser,$data,feof($fp));
}

xml_parser_free($xmlparser);
?>

xml_parse()

It parses an XML document

Example

<?php
$xmlparser = xml_parser_create();
$fp = fopen(‘test.xml’, ‘r’);
while ($xmldata = fread($fp, 4096)){
if (!xml_parse($xmlparser,$xmldata,feof($fp)))
echo xml_error_string(xml_get_error_code($xmlparser));
}
xml_parser_free($xmlparser);
?>