繁体   English   中英

如何从此URL检索特定的xml数据?

[英]How can i retrieve specific xml data from this URL?

我需要从此URL检索Identificador值

我尝试了几种方法,但到目前为止都没有成功。

这是代码:

function readxml($courseid,$datayear,$dataperiod,$datasemester){
    if ($dataperiod == 'a')
        $datasemester='1';

    $xmlUrl = 'https://clip.unl.pt/sprs?lg=pt&year=' . $datayear  .
        '&uo=97747&srv=rsu&p=' . $datasemester .
        '&tp=' . $dataperiod .
        '&md=3&rs=' . $courseid .
        '&it=1030123459';

    if (!function_exists('download_file_content')){
        function download_file_content($xmlStr){
            return implode( "",file($xmlStr));
        }
    }
    $xmlStr=download_file_content($xmlUrl);

    $xmlObj=new SimpleXMLElement(file_get_contents($xmlStr));

    foreach ($xmlObj->unidade_curricular->inscritos->aluno as $aluno) {
        $result=($aluno->identificador)."<br/>";
        echo $result;
    }
}

如果download_file_content不在if语句中,则不会被识别。 当前,我得到的错误是这样的:

Warning: file_get_contents(<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <edicao_lectiva nome="Algoritmos e Estruturas de Dados"> <ano>2008</ano> <lingua>pt</lingua> <tipo_de_periodo_lectivo>s</tipo_de_periodo_lectivo> <periodo_lectivo>1</periodo_lectivo> <unidade_curricular nome="Algoritmos e Estruturas de Dados"> <codigo>8145</codigo> <unidade_organica>Faculdade de Ciências e Tecnologia</unidade_organica> <departamento>Departamento de Informática</departamento> <grupodisciplinas>Ciência e Tecnologia da Programação</grupodisciplinas> <inscritos> <aluno numero="24250"> <nome>Adriano Constantino de Sousa Strumbudakis</nome> <identificador>a.strumbudakis</identificador> <codigo& in C:\moodle25\server\moodle\local\ecoclipaluno\somefile.php on line 106


Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\moodle25\server\moodle\local\ecoclipaluno\somefile.php:106 Stack trace: #0 C:\moodle25\server\moodle\local\ecoclipaluno\somefile.php(106): SimpleXMLElement->__construct('') #1 C:\moodle25\server\moodle\local\ecoclipaluno\somefile.php(137): readxml('8145', '2008', 's', '1') #2 C:\moodle25\server\moodle\local\ecoclipaluno\somefile.php(145): xpto('8145', '2008', 's', '1') #3 {main} thrown in C:\moodle25\server\moodle\local\ecoclipaluno\somefile.php on line 106

我究竟做错了什么?

我现在注意到,我的帖子缺少一些信息,因为我使用标签来表示要提取的值。

像这样:

<pre>
<?php

$xml = simplexml_load_string(file_get_contents('https://clip.unl.pt/sprs?lg=pt&year=2008&uo=97747&srv=rsu&p=1&tp=s&md=3&rs=8145&it=1030123459'));

print_r($xml);

?>
</pre>

输出:

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [nome] => Algoritmos e Estruturas de Dados
        )

    [ano] => 2008
    [lingua] => pt
    [tipo_de_periodo_lectivo] => s
    [periodo_lectivo] => 1

    ... snipped

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM