simplexml and accessing feedburner's : [duplicate]

耗尽温柔 提交于 2019-12-24 00:42:56

问题


I'm trying trying to use simplexml to read a feedburner xml. I can read every properties in the xml but not the keys with ':' in it. Example "feedburner:origLink". When I vardump the items, those keys with : doesn't show up. And I can't do like $s->item->feedburner:origLink.


回答1:


You're dealing with namespaces, and this Sitepoint article looks like a good long explanation. Or for a more concise version, look here in the PHP SimpleXML docs.

From the docs:

<?php
$xml = '<example xmlns:foo="my.foo.urn">
  <foo:a>Apple</foo:a>
  <foo:b>Banana</foo:b>
  <c>Cherry</c>
</example>';

$sxe = new SimpleXMLElement($xml);

$kids = $sxe->children('foo');
var_dump(count($kids));

$kids = $sxe->children('foo', TRUE);
var_dump(count($kids));

$kids = $sxe->children('my.foo.urn');
var_dump(count($kids));

$kids = $sxe->children('my.foo.urn', TRUE);
var_dump(count($kids));

$kids = $sxe->children();
var_dump(count($kids));
?>

Outputs:

int(0)
int(2)
int(2)
int(0)
int(1)



回答2:


If you're lazy and don't mind using google webservices, here's an easy way to get the full contents of a feedburner (or other) feed into php:

http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=100&q=http://feeds.feedburner.com/variety/headlines

You can then just json_decode it and it's all there in your object/array.



来源:https://stackoverflow.com/questions/3537655/simplexml-and-accessing-feedburners

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!