I have an XML file (below) that I am trying to parse with PHP.
<content>
<row label='DEV'>
<cell href="exUrl('URL')" status='0'>12345</cell>
<cell href="exUrl('URL')" status='1'>12345</cell>
<cell href="exUrl('URL')" status='1'>12345</cell>
<cell href="exUrl('URL')" status='1'>12345</cell>
<cell href="exUrl('URL')" status='1'>12345</cell>
</row>
<row label='DEV2'>
<cell href="exUrl('URL')" status='1'>56789</cell>
<cell href="exUrl('URL')" status='1'>56789</cell>
<cell href="exUrl('URL')" status='1'>56789</cell>
<cell href="exUrl('URL')" status='1'>56789</cell>
<cell href="exUrl('URL')" status='0'>56789</cell>
</row>
</content>
I'm currently using PHP to sum a number of 'rows' from an XML document (example below).
$dom = new DOMDocument();
$html = $dom->loadHTMLFile("XML.xml");
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('content');
$rows = $tables->item(0)->getElementsByTagName('row');
foreach ($rows as $row)
{
$cols = $row->getElementsByTagName('cell');
$totalValues += $cols->item(4)->nodeValue;
}
I've updated the for loop to include an if statement to check the status value, however this doesn't seem to be working.
foreach ($rows as $row)
{
$cols = $row->getElementsByTagName('cell');
$totalValues += $cols->item(4)->nodeValue;
if(($cols->item(4)->getElementsByTagName('status')->nodeValue) == 0) {
$flag = 0;
}
}
Can anyone assist with what I'm doing wrong here?
$cols->item(4)->getAttribute('status') == 0