Мне нужно получить значения Identificador от this URLКак я могу получить определенные данные XML из этого URL-адреса?
Я пробовал несколько подходов, но до сих пор не увенчался успехом.
Вот код:
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=103';
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
не будет распознано, если оно не было внутри, если заявление. В настоящее время ошибка, которую я получаю, такова:
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
Что я делаю неправильно?
Теперь я заметил, что в моем сообщении отсутствует какая-то информация, потому что я использую теги, чтобы сказать, какие значения я хочу извлечь.
дубликатом вопрос. В любом случае, полный ответ можно найти по адресу http://stackoverflow.com/a/21231638/1163786 –