我正在使用grab踢API,需要解析URL中的XML数据来获取嵌套的url并将其重定向到它。我似乎无法正确地获得XML解析。这是我现在所拥有的。
1. <?php
2. $songkick_artist = $_GET['id'];
3.
4. $xmlDoc = new DOMDocument();
5. $xmlDoc->load("http://api.songkick.com/api/3.0/search/artists.xml?query=$songkick_artist&apikey=songkickapikey");
6.
7. $x = $xmlDoc->documentElement;
8. foreach ($x->childNodes AS $item)
9. {
10. print $item->[]
11. print $item->nodeName . " = " . $item->nodeValue . "<br />";
12. }
13. ?>我得到了这个错误:
分析错误:第10行中的语法错误,意外的'[',期望T_STRING或T_VARIABLE或'{‘或'$’
解析XML信息的方法太多了,我现在很困惑。如果能在这方面提供任何帮助,我们将不胜感激。
更新4-13-11
我现在把代码改到这里了:
<?php
$doc = new DomDocument;
// We must validate the document before referring to the id
$doc->validateOnParse = true;
$doc->Load("http://api.songkick.com/api/3.0/search/artists.xml?query=$songkick_artist&apikey=songkickapikey");
echo "The element whose id is myelement is: " .
$doc->getElementById('myelement')->tagName . "\n";
?>当$doc->Load(“URL”)被触发时,我得到了一个403禁止的错误.
怎么回事?
发布于 2011-04-15 05:42:02
弄明白了。
$request_url = urlencode (“http://api.songkick.com/api/3.0/search/artists.xml?query=$songkick_artist&apikey=songkickapikey"”);$xml = simplexml_load_file($request_url)或模(“feed不加载”);$artist =$xml->结果->artist"uri";
urlencode是这方面的主要键,因为url不能正确地解析.
发布于 2011-04-13 22:01:58
您的问题是一个简单的解析错误。你在第10行缺少一个,这可能会解决这个问题?
发布于 2011-04-13 22:07:22
你想在第10行做什么?同步标记是错误的:print $item->[] $item是一个对象,所以您可以使用$item-> doSomeMethod ()来执行doSomeMethod,但是不能编写$item->[]。
https://stackoverflow.com/questions/5656182
复制相似问题