<?php
/*
* This is a simple example to show the reading process of a xml document.
* This example works with PHP4 and PHP5.
*
* This model was extracted from the PHP Manual at 'DOM Functions'
* chapter
*/
require_once("DOMAdapter.inc");
header("Content-Type: text/plain");
$xml = new DOMAdapter();
$doc = $xml->createDocument();
$doc->load("movies.xml");
$nodes = $doc->documentElement->childNodes;
echo "=== Movies ===\n\n";
for ($i = 0; $i < $nodes->length; $i++) {
$node = $nodes->item($i);
if ($node->nodeType != XML_ELEMENT_NODE)
continue;
$movie = $node->childNodes;
echo "Release Year: ".$node->getAttribute("year")."\n";
for ($j = 0; $j < $movie->length; $j++) {
$data = $movie->item($j);
if ($data->nodeType != XML_ELEMENT_NODE)
continue;
echo ucfirst($data->nodeName) .": ".$data->nodeValue."\n";
}
echo "\n\n";
}
?>
|