Sax with namespaces
saxns.php:
<?php
//use iso-8859-1 charset and @ as seperator
$parser_object = xml_parser_create_ns("ISO-8859-1","@");
//don't do CASE_FOLDING
xml_parser_set_option($parser_object, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser_object,"startElement","endElement");
//callback for start Elements
function startElement($parser_object, $elementname, $attribute) {
print "<ul>";
//split localname and namespaceURI
list($namespaceURI,$localName)= split("@",$elementname);
if ($localName) {
print "$localName \n";
print "NS: <font color='red'>$namespaceURI</font>\n";
} else {
print "$namespaceURI\n";
}
foreach ($attribute as $key => $value)
{
print "$key => $value; ";
}
}
//callback for end Element
function endElement($parser_object, $elementname) {
print "</ul>\n";
}
//open a filehandle to books.xml
if (!($fp = fopen("examples/books.xml", "r")));
//loop through data
while ($daten = fread($fp, 4096))
{
//parse the fragment
xml_parse($parser_object, $daten, feof($fp));
}
?>
Sax with namespaces
© copyright 2004 Bitflux GmbH