I'm looking for a way to pull through certain attributes from an XML element IF they exist. For a whole element, I'm using the following code which works fine:
However, I've got a disparity between the XML files which I'm trying to read, some have extra attributes which I'd like to add to an array if they are present. If they are not, I'll add a 0 or NULL value to the said array. Below is my (slightly modified) code for getting the attributes:
array_push($arr['deductions'], array($data->getAttribute("title"), $data->getAttribute("home"), $data->getAttribute("host")));
So, for instance, some XML files files have the extra attribute 'switch', if present I'd like to add that to the array, if not, add a 0 value.
Does anyone know a good way of doing this? I'd rather keep on using the DOM as I don't want to rewrite the whole routine using SimpleXML which looks like an easier alternative.
Thanks in advance for any help,