Forum Moderators: open
I have an XML problem. I have attached a simplified XML file.
I can display 'src' which would be www.cnn.com, www.yahoo.com and www.google.com and the associated 'e' which would be Description 1, Description 2, and Description 3.
I cannot display 'src url' which should be http://www.example.com, http://www.example.com, and http://www.example.com.
I don't know how to address this element properly. I read the file using curl and got the XML in an object and can see it in the echo of $oXML.
In my example I can display both 'src' and 'e' but not 'url'.
Any help would be appreciated!
<?php
//. . . fragment note download_page reads the file in curl
$sXML = download_page('http://www.example.com');
$oXML = new SimpleXMLElement($sXML);
echo $oXML;
foreach($oXML->rs as $oEntry){
for ( $idx = 0; $idx < 3; $idx += 1)
{
$src = $oEntry->r[$idx]->src;
echo $src;
$e = $oEntry->r[$idx]->e;
echo $e;
$url = $oEntry->r[$idx]->src->url;
echo $url;
}
}
// end of fragment
?>
[edited by: httpwebwitch at 8:49 am (utc) on Dec. 27, 2009]
[edit reason] examplified [/edit]
$oEntry->r[$idx]->src['@attributes']['url']
or
$oEntry->r[$idx]->src->attributes()['url']
documentation [php.net]
// original that didn't work
$url = $oEntry->r[$idx]->src->url;
echo $url;
// httpwebwitch code modified to work in my example
foreach($oEntry->r[$idx]->src->attributes() as $a => $url) {
echo $url,"\"\n";
}