Bill Sullivan
asked on
Receiving "Invalid argument supplied for foreach() " when parsing XML data
Hi:
I receive "Invalid argument supplied for foreach()" when I am parsing an XML file. The program goes ahead and parses out the data, but I need to understand the warning, then do what is needed to get rid of it. My code is below. It is the second 'foreach' that throws the warning (5th line).
Any help will be much appreciated!
foreach($data->STRUCTURES- >ROOF as $roofingItem) {
$count++;
}
while($i <= $count) {
foreach($data->STRUCTURES- >ROOF[$i]- >LINES->LI NE as $lineitem) {
$type=$data->STRUCTURES->R OOF[$i]->L INES->LINE [$ii]['typ e'];
if($type == "VALLEY") {
$valley=$valley + $data->STRUCTURES->ROOF[$i ]->LINES-> LINE[$ii][ 'length'];
}
if($type == "RIDGE") {
$ridge=$ridge + $data->STRUCTURES->ROOF[$i ]->LINES-> LINE[$ii][ 'length'];
}
if($type == "Eave") {
$eave=$eave + $data->STRUCTURES->ROOF[$i ]->LINES-> LINE[$ii][ 'length'];
}
if($type == "Rake") {
$rake=$rake + $data->STRUCTURES->ROOF[$i ]->LINES-> LINE[$ii][ 'length'];
}
if($type == "Flashing") {
$flashing=$flashing + $data->STRUCTURES->ROOF[$i ]->LINES-> LINE[$ii][ 'length'];
}
if($type == "StepFlash") {
$stepflash=$stepflash + $data->STRUCTURES->ROOF[$i ]->LINES-> LINE[$ii][ 'length'];
}
if($type == "HIP") {
$hip=$hip + $data->STRUCTURES->ROOF[$i ]->LINES-> LINE[$ii][ 'length'];
}
$ii++;
}
I receive "Invalid argument supplied for foreach()" when I am parsing an XML file. The program goes ahead and parses out the data, but I need to understand the warning, then do what is needed to get rid of it. My code is below. It is the second 'foreach' that throws the warning (5th line).
Any help will be much appreciated!
foreach($data->STRUCTURES-
$count++;
}
while($i <= $count) {
foreach($data->STRUCTURES-
$type=$data->STRUCTURES->R
if($type == "VALLEY") {
$valley=$valley + $data->STRUCTURES->ROOF[$i
}
if($type == "RIDGE") {
$ridge=$ridge + $data->STRUCTURES->ROOF[$i
}
if($type == "Eave") {
$eave=$eave + $data->STRUCTURES->ROOF[$i
}
if($type == "Rake") {
$rake=$rake + $data->STRUCTURES->ROOF[$i
}
if($type == "Flashing") {
$flashing=$flashing + $data->STRUCTURES->ROOF[$i
}
if($type == "StepFlash") {
$stepflash=$stepflash + $data->STRUCTURES->ROOF[$i
}
if($type == "HIP") {
$hip=$hip + $data->STRUCTURES->ROOF[$i
}
$ii++;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello Bill,
please describe what the error was and what was the helpfull solution in my comment or ask EE support to remove this Question and refund your points.