I can\'t seem to figure this one out. I have the following XML file:
Okay, looks like XPath was what I wanted. Here's what I came up with that does what I want:
load('file.xml')) {
if (checkIfBuildingExists($xmlDocument, $nameToFind)) {
echo "Found a red building!";
}
}
function checkIfBuildingExists($xdoc, $name) {
$result = false;
$xpath = new DOMXPath($xdoc);
$nodeList = $xpath->query('/targets/showcases/building', $xdoc);
foreach ($nodeList as $node) {
if ($node->getAttribute('name') == $name) {
$result = true;
}
}
return $result;
}
?>