I'm parsing an XML document which doesn't have a constant structure, some nodes may or may not exist, but my parsing is coded in a way that I always expect the whole structure. I've tried this:
$mKvFudbalDC->c4 = null;
$mKvFudbalDC->c5 = null;
$mKvFudbalDC->c6 = null;
$mKvFudbalDC->c68 = null;
$mKvFudbalDC->c69 = null;
$mKvFudbalDC->c4 = $choices[0]->attributes()->value;
$mKvFudbalDC->c5 = $choices[1]->attributes()->value;
$mKvFudbalDC->c6 = $choices[2]->attributes()->value;
$mKvFudbalDC->c68 = $choices[3]->attributes()->value;
$mKvFudbalDC->c69 = $choices[4]->attributes()->value
$mKvFudbalDC->save();
I was thinking that setting the variables to null will fix the problem, but no. For an example, if $choices[4]->attributes()->value
doesn't exist, I get an Undefined offset exception. I tried with isset()
in an if/else statement, but it turns out I had to do that with each and every member of the array, and it slows down the parsing and/or crashes nginx/apache and doesn't parse the XML to the end. Can this be overriden in any way?
Tiada ulasan:
Catat Ulasan