henry_osn 0 Denunciar post Postado Agosto 14, 2014 Olá a todos. Estou fazendo uma busca em um XML com SimpleXML. Consigo retornar a maioria dos nós, mas estou tendo problemas justamente com um deles: <abstract abstract-type="short" xml:lang="en"> echo $items['abstract'] . "<br/><br/>"; // NÃO CONSIGO EXIBIR O VALOR DESSE NÓ Meu XML: <article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <front> <article-meta> <title-group> <article-title xml:lang="pt">...</article-title> <article-title xml:lang="en">...</article-title> <article-title xml:lang="fr">...</article-title> <article-title xml:lang="es">...</article-title> </title-group> <contrib-group> <contrib contrib-type="author"> <name> <surname>...</surname> <given-names>...</given-names> </name> </contrib> </contrib-group> <abstract abstract-type="short" xml:lang="pt">...</abstract> </front> </article> PHP: foreach ($pid as $pids){ $url = 'http://www.scielo.br/scieloOrg/php/articleXML.php?pid='.$pids .'〈='.$getLang; $xml = simplexml_load_file_curl($url); foreach($xml->front->{'article-meta'} as $items) { echo $items->{'contrib-group'}->contrib->name->surname . ", "; echo $items->{'contrib-group'}->contrib->name->{'given-names'}. ". "; echo $items->{'title-group'}->{'article-title'}. "<br/>"; echo $items['abstract'] . "<br/><br/>"; // NÃO CONSIGO EXIBIR O VALOR DESSE NÓ } unset($items); } Acredito que seja um pequeno detalhe para acertar essa busca, mas como sou iniciante nesse assunto estou apanhando bastante. Agradeceria bastante se alguém puder ajudar com uma dica bem mastigadinha, rsrsr. Obrigado desde já, Henrique. Compartilhar este post Link para o post Compartilhar em outros sites
henry_osn 0 Denunciar post Postado Agosto 17, 2014 Oi pessoal? Alguém tem alguma dica? Acredito que o meu problema seja porque a palavra "abstract" é reservada no PHP. Por isso não consigo pegar o nó como fiz no trecho "echo $items->{'contrib-group'}->contrib->name->surname". Aí precisava de um forma alternativa para ler o nó, já que nenhuma das três que tentei resolveu: echo $items['abstract']; echo $items->abstract; echo $items->{'abstract'}; Obrigado mais uma vez. Compartilhar este post Link para o post Compartilhar em outros sites
Massaki 47 Denunciar post Postado Agosto 18, 2014 O quê aparece se dentro do while você dumpar o $items? Compartilhar este post Link para o post Compartilhar em outros sites
henry_osn 0 Denunciar post Postado Agosto 20, 2014 Vou colocar só uma linha do loop: object(SimpleXMLElement)#254 (14) { ["article-id"]=> array(2) { [0]=> string(23) "S0103-65641998000100058" [1]=> string(31) "10.1590/S0103-65641998000100058" } ["title-group"]=> object(SimpleXMLElement)#238 (1) { ["article-title"]=> object(SimpleXMLElement)#217 (0) { } } ["contrib-group"]=> object(SimpleXMLElement)#246 (1) { ["contrib"]=> object(SimpleXMLElement)#217 (3) { ["@attributes"]=> array(1) { ["contrib-type"]=> string(6) "author" } ["name"]=> object(SimpleXMLElement)#229 (2) { ["surname"]=> object(SimpleXMLElement)#220 (0) { } ["given-names"]=> object(SimpleXMLElement)#230 (0) { } } ["xref"]=> object(SimpleXMLElement)#250 (1) { ["@attributes"]=> array(2) { ["ref-type"]=> string(3) "aff" ["rid"]=> string(3) "A01" } } } } ["aff"]=> object(SimpleXMLElement)#245 (3) { ["@attributes"]=> array(1) { ["id"]=> string(3) "A01" } ["institution"]=> object(SimpleXMLElement)#217 (0) { } ["addr-line"]=> object(SimpleXMLElement)#250 (0) { } } ["pub-date"]=> array(2) { [0]=> object(SimpleXMLElement)#244 (4) { ["@attributes"]=> array(1) { ["pub-type"]=> string(3) "pub" } ["day"]=> string(2) "00" ["month"]=> string(2) "00" ["year"]=> string(4) "1998" } [1]=> object(SimpleXMLElement)#243 (4) { ["@attributes"]=> array(1) { ["pub-type"]=> string(4) "epub" } ["day"]=> string(2) "00" ["month"]=> string(2) "00" ["year"]=> string(4) "1998" } } ["volume"]=> string(1) "9" ["numero"]=> string(1) "1" ["fpage"]=> string(3) "275" ["lpage"]=> string(3) "301" ["copyright-statement"]=> object(SimpleXMLElement)#242 (0) { } ["copyright-year"]=> object(SimpleXMLElement)#241 (0) { } ["self-uri"]=> array(3) { [0]=> object(SimpleXMLElement)#240 (0) { } [1]=> object(SimpleXMLElement)#239 (0) { } [2]=> object(SimpleXMLElement)#237 (0) { } } ["abstract"]=> array(2) { [0]=> object(SimpleXMLElement)#218 (2) { ["@attributes"]=> array(1) { ["abstract-type"]=> string(5) "short" } ["p"]=> object(SimpleXMLElement)#250 (0) { } } [1]=> object(SimpleXMLElement)#231 (2) { ["@attributes"]=> array(1) { ["abstract-type"]=> string(5) "short" } ["p"]=> object(SimpleXMLElement)#250 (0) { } } } ["kwd-group"]=> object(SimpleXMLElement)#228 (1) { ["kwd"]=> array(8) { [0]=> object(SimpleXMLElement)#250 (1) { ["@attributes"]=> array(1) { ["lng"]=> string(2) "pt" } } [1]=> object(SimpleXMLElement)#217 (1) { ["@attributes"]=> array(1) { ["lng"]=> string(2) "pt" } } [2]=> object(SimpleXMLElement)#229 (1) { ["@attributes"]=> array(1) { ["lng"]=> string(2) "pt" } } [3]=> object(SimpleXMLElement)#230 (1) { ["@attributes"]=> array(1) { ["lng"]=> string(2) "pt" } } [4]=> object(SimpleXMLElement)#220 (1) { ["@attributes"]=> array(1) { ["lng"]=> string(2) "en" } } [5]=> object(SimpleXMLElement)#232 (1) { ["@attributes"]=> array(1) { ["lng"]=> string(2) "en" } } [6]=> object(SimpleXMLElement)#233 (1) { ["@attributes"]=> array(1) { ["lng"]=> string(2) "en" } } [7]=> object(SimpleXMLElement)#260 (1) { ["@attributes"]=> array(1) { ["lng"]=> string(2) "en" } } } } } Obrigado. Compartilhar este post Link para o post Compartilhar em outros sites
William Bruno 1501 Denunciar post Postado Agosto 20, 2014 abstract é outro array: ["abstract"]=> array(2) { [0]=>vc pode fazer outro loop para listar o conteúdo dele. Compartilhar este post Link para o post Compartilhar em outros sites
henry_osn 0 Denunciar post Postado Setembro 11, 2015 Olá há todos, por motivos de força maior esse projeto ficou um tempo parado e agora retornei a ele.Consegui exibir o nó em questão fazendo assim: foreach($xml->front->{'article-meta'}->abstract as $items){ $abstract = $items->p; echo $abstract; } onde $items->p é o nó que contém o conteúdo que quero. Obrigado a todos e desculpe a demora pela resposta. Compartilhar este post Link para o post Compartilhar em outros sites