libxml2 is a software library for parsing XML documents. It is also the basis for the libxslt library which processes XSLT-1.0 stylesheets.
libxml_use_internal_errors()
It disable libxml errors and allow user to fetch error information as needed
Example
<?php
libxml_use_internal_errors()
?>
libxml_set_streams_context()
It set the streams context for the next libxml document load or write
libxml_set_external_entity_loader()
It changes the default external entity loader
libxml_get_last_error()
It returns last error from libxml
Example
<?php
libxml_get_last_error()
?>
libxml_get_errors()
It returns array of errors
Example
<?php
libxml_get_errors()
?>
libxml_disable_entity_loader()
It disable the ability to load external entities
Example
<?php
libxml_disable_entity_loader()
?>
libxml_clear_errors()
It clears the libxml error buffer
Example
<?php
libxml_clear_errors()
?>
xml_set_unparsed_entity_decl_handler()
Example
<?php
$xmlparser=xml_parser_create();
function char($xmlparser,$data) {
echo $data;
}
function unparsed_ent_handler_func($xmlparser,$entname,$base,$sysID,$pubID,$notname){
echo $entname.$sysID.$pubID.$notname.
}
xml_set_character_data_handler($xmlparser,”char”);
xml_set_unparsed_entity_decl_handler($xmlparser,”unparsed_ent_handler_func”);
$fp=fopen(“test.xml”,”r”);
while ($data=fread($fp,4096)) {
xml_parse($xmlparser,$data,feof($fp)) or die(“Failed”);
}
xml_parser_free($xmlparser);
?>