Tag Archives: XML Parser

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

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

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

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

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

xml_get_error_code()

It returns XML parser error code

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

?>