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);
?>

Share

xml_set_default_handler()

It set up default handler

Example

<?php
$xmlparser=xml_parser_create();
xml_set_default_handler($xmlparser,”default”);
$fp=fopen(“book.xml”,”r”);
while ($data=fread($fp,4096)){
xml_parse($xmlparser,$data,feof($fp));
}
xml_parser_free($xmlparser);
?>

Share

xml_set_character_data_handler()

It set up character data handler

Example

<?php
$parser=xml_parser_create();
function func($parser,$val) {
echo $val;
}
xml_set_character_data_handler($parser,”func”);
$fp=fopen(“book.xml”,”r”);
while ($data=fread($fp,4096)){
xml_parse($parser,$data,feof($fp)) ;
}
xml_parser_free($parser);
?>

Share

xml_parser_free()

Free an XML parser

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);
?>

Share

xml_parser_create()

It create an XML parser

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);
?>

Share

xml_parser_create_ns()

It create an XML parser with namespace support

Example

<?php
$xmlparser = xml_parser_create_ns();
$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);
?>

Share

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);
?>

Share

xml_parse_into_struct()

It parses XML data into an array structure

Example

<?php
$xmlfile = ‘book.xml’;
$xmlparser = xml_parser_create();
$fp = fopen($xmlfile, ‘r’);
$xmldata = fread($fp, 4096);
xml_parse_into_struct($xmlparser,$xmldata,$values);
xml_parser_free($xmlparser);
echo “<pre>”;print_r($values);
?>

Share