I have a small XML file:
<wddxPacket version='1.0'>
<header/>
<data>
<struct type='coldfusion.runtime.ArgumentCollection'>
<var name='HEADLINE'>
<string>Richard Barret's Articles on Leadership and High Performance Organisations</string>
</var>
</struct>
</data>
</wddxPacket>
I'm trying to use PHP SimpleXML and xpath to extract the value between the string element in the var name HEADLINE element. This code works:
// Location of the XML file on the file system
$file = 'http://10.10.200.37/skins/importscript/41802.xml';
$xml = simplexml_load_file($file);
// CREATE THE ARRAYS FOR EACH XML ELEMENT NEEDED
$title = $xml->xpath('//var[@name="HEADLINE"]');
echo "<p>";
print_r($title);
echo "</p>";
The problem is that it returns not only the value but also all the array information. As in:
Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => HEADLINE ) [string] => Richard Barret's Articles on Leadership and High Performance Organisations ) )
How can I get it to return just the value and nothing else?
If I replace print_r
with echo $title;
I get the word Array on the page instead of the value. If I try echo $title[0];
I get nothing at all.
I've tried so many things now can't think of anything else! What am I doing wrong? Could anyone point me in the right direction? Thanks!