开发者

PHP for XML with namespaces and attributes

I've been playing arround nearly all day for get开发者_如何转开发ting attributes of xml item which is is namespaces. Part of XML: ...

<item>
      <title>name</title>
      <link>link</link>
      <media:thumbnail url="url" height="133" width="200"  />
</item>

... What I managed to get is title and link with following script:

$z = new XMLReader;
$z->open($gLink);
$doc = new DOMDocument;
while ($z->read() && $z->name !== 'item');
$node = simplexml_import_dom($doc->importNode($z->expand(), true));
$gTitle = $node->title;
$gLink = $node->link;
$gThumb = $node->children('media', true)->thumbnail->children();
print_r($gThumb);

After printing $gThumb I get:

SimpleXMLElement Object ( [@attributes] => Array ( [url] => url [height] => 133 [width] => 200 ) ) 

And what I need to get is url from attribute. I would be very pleased to get any help.


If its a SimpleXMLElement then use

$foo = (string)$gThumb->attributes()->url
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜