当我在浏览器中添加此行时,它会显示XML
结构
然后我有PHP
文件call.php
:
$root = simplexml_load_file('http://api.elsevier.com/content/search/scidir?query=cmm&httpAccept%28application/atom+xml&apiKey=[validApiKey]');
// Saving the whole modified XML to a new filename
$root->asXml('results.xml');
?>
<?php
header( "Content-Type: application/vnd.ms-excel" );
header( "Content-disposition: attachment; filename=spreadsheet.xls" );// put your file name here
$url = 'updated.xml'; // xml file location with file name
if (file_exists($url)) {
$xml = simplexml_load_file($url);
echo 'Title'."\t" . 'Author'."\t" . 'Publisher'."\t" . 'PDF'."\t\n";
foreach($xml->document as $books)
{
echo $books->title."\t" . $books->author."\t" . $books->publisher."\t" . $books->pdf."\n";
}
}
?>
它给了我错误:
警告:simplexml_load_file():
http://api.elsevier.com/content/search/scidir?query=cmm&httpAccept%28application/atom+xml&apiKey=[validApiKey]:1:
解析器错误:期望开始标记,&#39;&lt;&#39;在第4行的D:\ xampp \ htdocs \ call.php中找不到
当我使用其他链接尝试相同的操作时,这些链接会为我提供另一个链接显示的相同XML
结构,并创建results.xml
文件。
我不知道为什么一个链接没有问题,而另一个链接没有问题。
感谢。
我的编辑: xml在浏览器中显示:
<search-results><opensearch:totalResults>9616259</opensearch:totalResults><opensearch:startIndex>0</opensearch:startIndex><opensearch:itemsPerPage>25</opensearch:itemsPerPage><opensearch:Query role="request" searchTerms="((cmm) OR (information) OR (of) OR (description) OR (level))" startPage="0"/><link ref="self" href="http://api.elsevier.com/content/search/scidir?start=0&count=25&query=%28%28cmm%29+OR+%28information%29+OR+%28of%29+OR+%28description%29+OR+%28level%29%29&httpAccept(application/xml&apiKey=472d9f703a39bf442e9912860bc91f01" type="application/xml"/><link ref="first" href="http://api.elsevier.com/content/search/scidir?start=0&count=25&query=%28%28cmm%29+OR+%28information%29+OR+%28of%29+OR+%28description%29+OR+%28level%29%29&httpAccept(application/xml&apiKey=472d9f703a39bf442e9912860bc91f01" type="application/xml"/><link ref="next" href="http://api.elsevier.com/content/search/scidir?start=25&count=25&query=%28%28cmm%29+OR+%28information%29+OR+%28of%29+OR+%28description%29+OR+%28level%29%29&httpAccept(application/xml&apiKey=472d9f703a39bf442e9912860bc91f01" type="application/xml"/><link ref="last" href="http://api.elsevier.com/content/search/scidir?start=5975&count=25&query=%28%28cmm%29+OR+%28information%29+OR+%28of%29+OR+%28description%29+OR+%28level%29%29&httpAccept(application/xml&apiKey=472d9f703a39bf442e9912860bc91f01" type="application/xml"/><entry><link ref="self" href="http://api.elsevier.com/content/article/pii/S0025775316306674"/><link ref="scidir" href="http://www.sciencedirect.com/science/article/pii/S0025775316306674"/><dc:identifier>DOI:10.1016/j.medcli.2016.11.027</dc:identifier><eid>1-s2.0-S0025775316306674</eid><prism:url>http://api.elsevier.com/content/article/pii/S0025775316306674</prism:url><dc:title>Importancia del anión GAP ante la falta de información clínica: descripción de un caso clínico de intoxicación oral grave por metanol</dc:title><dc:creator>Ana Isabel, Rodríguez Ruitiña</dc:creator><prism:publicationName>Medicina Clínica</prism:publicationName><prism:issn>00257753</prism:issn><prism:volume>148</prism:volume><prism:issueIdentifier>5</prism:issueIdentifier><prism:coverDate>2017-03-03</prism:coverDate><prism:coverDisplayDate>3 March 2017</prism:coverDisplayDate><prism:startingPage>238</prism:startingPage><prism:endingPage>239</prism:endingPage><prism:doi>10.1016/j.medcli.2016.11.027</prism:doi><openaccess>0</openaccess><openaccessArticle>false</openaccessArticle><openArchiveArticle>false</openArchiveArticle><openaccessUserLicense/><pubType>Carta al Editor</pubType><pii>S0025-7753(16)30667-4</pii><authors><author><given-name>Ana Isabel</given-name><surname>Rodríguez Ruitiña</surname></author><author><given-name>José Gregorio</given-name><surname>Zorrilla Riveiro</surname></author><author><given-name>Dolors</given-name><surname>García Pérez</surname></author></authors><prism:teaser/></entry>