It changes the default external entity loader
Tag Archives: Functions
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);
?>
xml_set_start_namespace_decl_handler()
xml_set_processing_instruction_handler()
Example
<?php
$xmlparser=xml_parser_create();
function char($xmlparser,$data) {
echo $data;
}
function pi_handler_func($xmlparser, $target, $data) {
echo $target.$data;
}
xml_set_character_data_handler($xmlparser,”char”);
xml_set_processing_instruction_handler($xmlparser, “pi_handler_func”);
$fp=fopen(“book.xml”,”r”);
while ($data=fread($fp,4096)){
xml_parse($xmlparser,$data,feof($fp));
}
xml_parser_free($xmlparser);
?>
xml_set_object()
Example
<?php
class XMLParser{
var $xmlparser;
function XMLParser(){
$this->xmlparser = xml_parser_create();
xml_set_object($this->xmlparser, $this);
xml_set_character_data_handler($this->xmlparser,”char”);
xml_set_element_handler($this->xmlparser, “start_tag”,”end_tag”);
}
function parse($data){
xml_parse($this->xmlparser, $data);
}
function parse_File($xmlfile){
$fp = fopen($xmlfile, ‘r’);
while ($xmldata = fread($fp, 4096)){
if(!xml_parse($this->xmlparser, $xmldata)){
die(“Failed”);
}
}
}
function start_tag($xmlparser, $tag, $attributes){
print $tag . “n”;
}
function end_tag(){}
function char($xmlparser,$data){
echo $data . “n”;
}
function close_Parser(){
xml_parser_free($this->xmlparser);
}
}
$myxmlparser = new XMLParser();
$myxmlparser->parse_File(“book.xml”);
$myxmlparser->close_parser();
?>
xml_set_notation_decl_handler()
Example
<?php
$parser=xml_parser_create();
function char($parser,$data){
echo $data;
}
function not_decl_func($parser,$not,$base,$sysID,$pubID) {
echo $not.$sysID.$pubID;
}
xml_set_character_data_handler($parser,”char”);
xml_set_notation_decl_handler($parser, “not_decl_func”);
$fp=fopen(“test.xml”,”r”);
while ($data=fread($fp,4096)) {
xml_parse($parser,$data,feof($fp)) or die(“Failed”);
}
xml_parser_free($parser);
?>