Hi all
Ok, I've pretty much cracked reading in and outputting XML data. Now, I'm trying to change the odd node value here and there but am not having a lot of luck.
Here's the code:
$xmlDoc = new DOMDocument();
$xmlDoc->load('furnace.xml');
$xmlGigs = $xmlDoc->getElementsByTagName("gig");
$calendar = array(
"title" => array(),
);
$i = 0;
foreach ($xmlGigs as $Gig)
{
$calendar['title'][$i] = $Gig->getElementsByTagName("title");
if ($calendar['title'][$i]->length == 0)
{
// the value is null so change it to "unknown"
$calendar['title'][$i]->item(0)->nodeValue = "unknown";
}
echo $calendar['title'][$i]->item(0)->nodeValue . "<br/>";
++$i;
}
Basically, I just want to read in all the instances of <title></title> into the $calendar array. Sometimes, these don't exist on the XML sheet though (deliberately) so, in cases like this, I want to replace it with "unknown".
Can't get it to work though - I just get these errors:
Strict Standards: Creating default object from empty value
Notice: Trying to get property of non-object
Can anyone help?