<?php
$dom = new domDocument;
$dom->load('data.xml');
?>
<?php
$domxsl = domDocument::load('stylesheet.xsl');
$proc = new xsltProcessor;
$proc->importStyleSheet($domxsl);
echo $proc->transformToXML($dom);
?>
<?php
$ctx = new domXPath($dom);
$result = $ctx->query('/breakfast_menu/food[@itemno > 3]/price/text()');
foreach($result as $node) {
echo $node->nodeValue."<br />\n";
}
?>
<?php
class entities_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = htmlentities($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
stream_filter_register("entities", "entities_filter");
echo "<pre>";
readfile("php://filter/read=entities/resource=menu.xml");
echo "</pre>";
?>
<?php
$menu = simplexml_load_file('menu.xml');
foreach ($menu->food as $item) {
echo "{$item->price}\t{$item->name}<br />\n";
}
?>