Thursday, 12 September 2013

Parsing empty XML elements in PHP

Parsing empty XML elements in PHP

PHP newbie here. I'm parsing a long XML file, setting each tag to a
variable. If the element's tag is empty, I want to assign it the value
"N/A"
I'm wondering if there's a more concise way to do this than my current
approach:
$elements = array()
$propertyOwner = $report->PropertyProfile->PrimaryOwnerName[0];
array[] = $propertyOwner;
$propertyAddress = $report->PropertyProfile->SiteAddress[0];
array[] = $propertyAddress;
...
for($i=0; $i<count($elements); $i++) {
if (array[i] === '') {
array[i] = 'N/A');
}
}

No comments:

Post a Comment