Files
archived-presentations/slides/php5xml2/dom_access3.php
2005-05-16 23:53:57 +00:00

17 lines
490 B
PHP

<?php
$dom = new domDocument();
$dom->load(dirname(__FILE__) . "/thedata.xml");
$root = $dom->documentElement; // <forum>
foreach ($root->childNodes as $child) {
if ($child->nodeType == XML_ELEMENT_NODE) { // <item>
$id = $child->getAttribute("id"); // <item id="value">
echo "item #{$id}<br />";
foreach ($child->childNodes as $c2) { // item nodes
if ($c2->nodeType == XML_ELEMENT_NODE) { // <title>, <link>
echo "{$c2->nodeName} => {$c2->nodeValue}<br />";
}
}
}
}
?>