Files
archived-presentations/slides/php5xml/dom_access3.php
Ilia Alshanetsky bc1df0f093 PHP|Works talks.
2004-10-13 14:53:59 +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 />";
}
}
}
}
?>