Code has been added to clipboard!
Reading XML File with PHP
Example
<?php
$q = $_GET["q"];
$xml_doc = new DOMDocument();
$xml_doc->load("cd_list.xml");
$x = $xml_doc->getElementsByTagName('MUSICIAN');
for ($i=0; $i< = $x->length-1; $i++) {
//Set only to process nodes from elements
if ($x->item($i)->nodeType==1) {
if ($x->item($i)->childNodes->item(0)->nodeValue == $q) {
$y=($x->item($i)->parentNode);
}
}
}
$cd = ($y->childNodes);
for ($i=0; $i<$cd->length; $i++) {
//Set only to process nodes from elements
if ($cd->item($i)->nodeType==1) {
echo("<b>" . $cd->item($i)->nodeName . ":</b> ");
echo($cd->item($i)->childNodes->item(0)->nodeValue);
echo("<br>");
}
}
?>