I'm guessing that your childNodes
is including text nodes along with the XML tag nodes due to the white space in between tags. This can result in a count of childNodes
twice what you expect it to be. You should check the nodeType
to make sure it isn't a text node before attempting to get its attributes.
Possibly in here:
for($x = 0; $x < count($node->childNodes); $x++)
{
// Verify that you're not working on a text node (type 3 TEXT_NODE)
if($node->nodeType != 3 && $node->childNodes->item($x)->getAttribute("name") == $filename)
{
$target = $node->childNodes->item($x);
echo "Target found.
";
}
else
{
echo "Searching for target...
";
}
}