views:

1183

answers:

2

I am Parasing XML currently using:

$data = simplexml_load_string($xmlFile);
foreach($data->item as $key => $current){
   echo($current);
}

However I'm wondering, if a hit an element that looks like this:

<thumbnail url="http://foo.bar" height="225" width="300"/>

How do i pull the inner parts of this? (height, url, width)

Thanks!

+3  A: 
foreach($data->item->thumbnail as $thumbnail) {

    $url = $thumbnail['url'];
    $height = $thumbnail['height'];
    $width = $thumbnail['width'];
}
rojoca
Cheers. Didn't know I could navigate through the attribute like that.
Frederico
+1  A: 

In case you don't know how many attributes there will be...

foreach ($data->item->thumbnail->attributes() as $key => $value) {
    $attr[$key] = (string)$value;
}
Randell