2017-07-08 51 views
-2

你能帮助我吗?我如何阅读这个XML?

我需要阅读本文件:

我试过这样:

$ XML =使用simplexml_load_file( 'http://api.crossref.org/works/10.18468/pracs.2016v9n3.p99-119/transform/application/vnd.crossref.unixsd+xml');

echo $ xml-> journal_metadata-> full_title;

我不知道如何获得特定标签的价值。

我需要阅读:Click to see

+0

_ “但它doesn't工作” _是你有具体的问题.... – Jeff

+0

和相当的简短描述无,这样,没有人可以帮助你(免除你的工作..)。你有没有遇到任何问题的代码?你有什么尝试? – Jeff

+0

你有没有使用过“xml parser php”? – Jeff

回答

-1

首先,你从遥远的服务器加载文件:

$file = @file_get_contents('http://api.crossref.org/works/10.18468/pracs.2016v9n3.p99-119/transform/application/vnd.crossref.unixsd+xml'); 
if ($file===FALSE) 
{ 
    die ("error getting the content of the file"); 
} 

然后,您解析XML和使用SimpleXML将其解压缩到一个对象:

$o= simplexml_load_string ($file); 

最后,你移动你的对象树,直到你到达预期的目的地

echo "<pre>"; 
$intended_obj = $o->query_result->body->query->doi_record->crossref->journal->journal_article->doi_data; 
print_r($intended_obj->resource); 
print_r($intended_obj->collection); 
echo "</pre>"; 

应该输出:

SimpleXMLElement Object 
(
    [0] => https://periodicos.unifap.br/index.php/pracs/article/view/2791 
) 
SimpleXMLElement Object 
(
    [@attributes] => Array 
     (
      [property] => crawler-based 
     ) 
    [item] => SimpleXMLElement Object 
     (
      [@attributes] => Array 
       (
        [crawler] => iParadigms 
       ) 
      [resource] => https://periodicos.unifap.br/index.php/pracs/article/viewFile/2791/haliadorav9n3.pdf 
     ) 
) 

祝你好运,