0
我有一个特殊标记的XML RSS我不知道如何阅读的第二部分,在这种情况下,子类别如何阅读标签具有两个属性
XML RSS:
<?xml version="1.0" encoding="UTF-8"?>
<channel>
<category text="Category">
<category text="Subcategory"/>
</category>
</channel>
</rss>
PHP
//this gives the category
$category = $feed->channel->category->attributes();
echo $category . '<br>';
//I tried this but only gives category and I need subcategory too
foreach ($feed->channel->category->attributes() as $item) {
echo $item . '<br>';
}
有一个{在第二个foreach中丢失。我复制粘贴添加这个,它不起作用,它只给出类别 – Nrc 2014-08-30 13:41:39
刚刚重新编辑,以允许嵌套类别元素 – 2014-08-30 14:00:27
它的工作原理,但我不明白。你能解释一下吗?如果他们是两个元素,为什么你需要迭代到达第一个? – Nrc 2014-08-30 14:16:56