I've been looking around for a solution for this but can't find one anywhere.
I am trying to parse a XML
file, but certain TagNames
are missing from the XML
. Some posts suggest using the object length but this doesn't work either.
if ($xmlObject->item($i)->getElementsByTagName('image1')->item(0)->childNodes->item(0)->length > 0) {
$product_image1 = $xmlObject->item($i)->getElementsByTagName('image1')->item(0)->childNodes->item(0)->nodeValue;
} else {
$product_image1 = "";
}
Notice: Trying to get property of non-object in /home/s/public_html/import_xml.php on line 72
Fatal error: Call to a member function item() on a non-object in /home/s/public_html/import_xml.php on line 72
The error is because <image1>
is missing from the XML.
Any ideas on a fix?