Q:

Setting Parent Node Variable in SimpleXML and XPath

I am working with PHP and SimpleXML/XPath, and I'm just wondering how to set a certain parent (with a certain attribute value) equal to a variable, which I could use in a 'foreach'?
I'm currently getting this error:
Notice: Array to string conversion

and this output
Array

Thanks for any leads.  
Here is the php code:
<?php
$url = "test_b.xml";

$xml = simplexml_load_file($url);

$xml_report_abbrev_b = $xml->xpath('//poster[@name="U-Verify"]')[0];

if($xml_report_abbrev_b){
    foreach($xml_report_abbrev_b as $node_a) {
        echo '<h1>'.$node_a->xpath('/full_image/@url').'</h1>';
    }
} else {
    echo 'XPath query failed';  
}

?>

Here's the xml:
<data>
  <poster name="U-Verify" id="uverify">
    <full_image url="u-verify.jpg"/>
    <full_other url=""/>
  </poster>
  <poster name="Minimum" id="min">
    <full_image url="min.jpg"/>
    <full_other url="spa_min.jpg"/>
  </poster>
</data>

A:

Using SimpleXML's element access and attribute access directly instead of using the XPath query will make the code simpler and perform better.
Your code could be reduced to...
$xml_report_abbrev_b = $xml->xpath('//poster[@name="U-Verify"]');

if($xml_report_abbrev_b){
    echo '<h1>'.$xml_report_abbrev_b[0]->full_image['url'].'</h1>';
} else {
    echo 'XPath query failed';
}

Note the way the echo line says - with the <poster> element you found from the XPath expression, use the <full_image> element and fetch the url attribute.
I also moved the [0] into the if because if the XPath didn't find a value, this produced an error as there isn't any data to get a value from.
This outputs...
<h1>u-verify.jpg</h1>

