I'm trying to read an XML file using PHP. The XML file is a report that comes from somewhere else. Everything works fine except when the XML file ends up having multiple tags with the same name within the 'ReportItem' tags.
For example, when there is only 1 tag, the contents of that tag are correctly displayed. But when there is more than 1 tag, it displays 'ARRAY(0x996c840)'.
My XML looks like this:
<Scan>
<Report>
<ReportHost>
<ReportItem>
...
<see_also>http://google.com</see_also>
...
</ReportItem>
<ReportItem>
...
<see_also>http://google.com</see_also>
<see_also>http://google.com</see_also>
<see_also>http://google.com</see_also>
<see_also>http://google.com</see_also>
<see_also>http://google.com</see_also>
...
</ReportItem>
...
</ReportHost>
</Report>
</Scan>
My Code looks like this:
//Load the XML File
$xml = simplexml_load_file($path);
foreach ($xml->ReportHost as $reportHost)
{
$x = 1;
foreach ($reportHost->ReportItem as $reportItem)
{
...
$ARCHIVES['SEE_ALSO'][$x] = str_replace( "\\n", '<br />', $reportItem->see_also);
...
}
}
I've tried many different things, but nothing seems to work. Even just trying to display it doesn't even work.
I've tried:
print_r($xml->xpath("//see_also"));
But that still only gives me the contents if there is only 1 tag, otherwise I get the same 'ARRAY(0x996c840)' result.
I also tried:
$z = 0;
while (isset($reportItem->see_also[$z]) AND ($reportItem->see_also[$z] != ""))
{
echo "See Also: " . $reportItem->see_also[$z] . "\n";
$z++;
}
But I always get the same thing.
I even tried using an 'xml_to_array' function from xmlutils.php which was a script I downloaded from:
http://pynej.blogspot.com/2010/02/convert-xml-to-array-and-array-to-xml.html
But it still always displays 'ARRAY(0x996c840)' instead of the contents.
I really need someones help to see what I'm doing wrong. Thanks in advance for your help!