IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[SimpleXML] Parsing xml depuis url


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre actif
    Inscrit en
    Avril 2006
    Messages
    702
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 702
    Points : 289
    Points
    289
    Par défaut [SimpleXML] Parsing xml depuis url
    Bonjour a tous,

    je voudrais recuperer un fichier XML a partir d'une URL et le parser.

    Pour ce faire j'utilise ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?php
     
    $url = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=23565222";
     
    $xml = simplexml_load_file($url);
     
    foreach ($xml->doc as $doc) {
     
        echo '<h2>' . $doc->Id . '</h2>';
        echo '<p>' . $doc->PubDate . '</p>';
    }
    ?>

    Pour demarrer je voudrais recuperer le champs ID et Pubdate
    mais j'ai page blanche...
    Quelqu'un sait c que je fait mal?

    D'avance merci

    le fichier XML est:

    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    <eSummaryResult>
    <DocSum>
    <Id>23565222</Id>
    <Item Name="PubDate" Type="Date">2013</Item>
    <Item Name="EPubDate" Type="Date">2013 Apr 2</Item>
    <Item Name="Source" Type="String">PLoS One</Item>
    <Item Name="AuthorList" Type="List">
    <Item Name="Author" Type="String">Lalremruata A</Item>
    <Item Name="Author" Type="String">Ball M</Item>
    <Item Name="Author" Type="String">Bianucci R</Item>
    <Item Name="Author" Type="String">Welte B</Item>
    <Item Name="Author" Type="String">Nerlich AG</Item>
    <Item Name="Author" Type="String">Kun JF</Item>
    <Item Name="Author" Type="String">Pusch CM</Item>
    </Item>
    <Item Name="LastAuthor" Type="String">Pusch CM</Item>
    <Item Name="Title" Type="String">
    Molecular identification of falciparum malaria and human tuberculosis co-infections in mummies from the fayum depression (lower egypt).
    </Item>
    <Item Name="Volume" Type="String">8</Item>
    <Item Name="Issue" Type="String">4</Item>
    <Item Name="Pages" Type="String">e60307</Item>
    <Item Name="LangList" Type="List">
    <Item Name="Lang" Type="String">English</Item>
    </Item>
    <Item Name="NlmUniqueID" Type="String">101285081</Item>
    <Item Name="ISSN" Type="String"/>
    <Item Name="ESSN" Type="String">1932-6203</Item>
    <Item Name="PubTypeList" Type="List">
    <Item Name="PubType" Type="String">Journal Article</Item>
    </Item>
    <Item Name="RecordStatus" Type="String">PubMed - in process</Item>
    <Item Name="PubStatus" Type="String">ppublish+epublish</Item>
    <Item Name="ArticleIds" Type="List">
    <Item Name="doi" Type="String">10.1371/journal.pone.0060307</Item>
    <Item Name="pii" Type="String">PONE-D-12-39756</Item>
    <Item Name="pubmed" Type="String">23565222</Item>
    <Item Name="pmc" Type="String">PMC3614933</Item>
    <Item Name="eid" Type="String">23565222</Item>
    <Item Name="rid" Type="String">23565222</Item>
    <Item Name="pmcid" Type="String">pmc-id: PMC3614933;</Item>
    </Item>
    <Item Name="DOI" Type="String">10.1371/journal.pone.0060307</Item>
    <Item Name="History" Type="List">
    <Item Name="received" Type="Date">2012/12/16 00:00</Item>
    <Item Name="accepted" Type="Date">2013/02/25 00:00</Item>
    <Item Name="epublish" Type="Date">2013/04/02 00:00</Item>
    <Item Name="entrez" Type="Date">2013/04/09 06:00</Item>
    <Item Name="pubmed" Type="Date">2013/04/09 06:00</Item>
    <Item Name="medline" Type="Date">2013/04/09 06:00</Item>
    </Item>
    <Item Name="References" Type="List"/>
    <Item Name="HasAbstract" Type="Integer">1</Item>
    <Item Name="PmcRefCount" Type="Integer">0</Item>
    <Item Name="FullJournalName" Type="String">PloS one</Item>
    <Item Name="ELocationID" Type="String">doi: 10.1371/journal.pone.0060307</Item>
    <Item Name="SO" Type="String">2013;8(4):e60307</Item>
    </DocSum>
    </eSummaryResult>

  2. #2
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 101
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 101
    Points : 8 211
    Points
    8 211
    Billets dans le blog
    17
    Par défaut
    Je ne vois pas d'élément <Doc>.

    Fais un print_r( ) sur $xml.
    Un problème exposé clairement est déjà à moitié résolu
    Keep It Smart and Simple

  3. #3
    Membre actif
    Inscrit en
    Avril 2006
    Messages
    702
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 702
    Points : 289
    Points
    289
    Par défaut
    Salut,

    le print_r donne ceci;

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SimpleXMLElement Object ( [DocSum] => SimpleXMLElement Object ( [Id] => 23565222 [Item] => Array ( [0] => 2013 [1] => 2013 Apr 2 [2] => PLoS One [3] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => AuthorList [Type] => List ) [Item] => Array ( [0] => Lalremruata A [1] => Ball M [2] => Bianucci R [3] => Welte B [4] => Nerlich AG [5] => Kun JF [6] => Pusch CM ) ) [4] => Pusch CM [5] => Molecular identification of falciparum malaria and human tuberculosis co-infections in mummies from the fayum depression (lower egypt). [6] => 8 [7] => 4 [8] => e60307 [9] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => LangList [Type] => List ) [Item] => English ) [10] => 101285081 [11] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => ISSN [Type] => String ) ) [12] => 1932-6203 [13] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => PubTypeList [Type] => List ) [Item] => Journal Article ) [14] => PubMed - in process [15] => ppublish+epublish [16] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => ArticleIds [Type] => List ) [Item] => Array ( [0] => 10.1371/journal.pone.0060307 [1] => PONE-D-12-39756 [2] => 23565222 [3] => PMC3614933 [4] => 23565222 [5] => 23565222 [6] => pmc-id: PMC3614933; ) ) [17] => 10.1371/journal.pone.0060307 [18] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => History [Type] => List ) [Item] => Array ( [0] => 2012/12/16 00:00 [1] => 2013/02/25 00:00 [2] => 2013/04/02 00:00 [3] => 2013/04/09 06:00 [4] => 2013/04/09 06:00 [5] => 2013/04/09 06:00 ) ) [19] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => References [Type] => List ) ) [20] => 1 [21] => 0 [22] => PloS one [23] => doi: 10.1371/journal.pone.0060307 [24] => 2013;8(4):e60307 ) ) )

  4. #4
    Membre actif
    Inscrit en
    Avril 2006
    Messages
    702
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 702
    Points : 289
    Points
    289
    Par défaut
    salut

    j'arrive a voir quelques champs mais j'arrive pas a extraire les champs qui sont loin dans l'arbre. Je m'explique

    avec ce code j'arrive a sortir l'id et la date:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?php
     
    $url = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=23565222";
     
    $xml = simplexml_load_file($url);
     
     foreach ($xml->DocSum as $doc) {
        echo '<h2>' . $doc->Id . '</h2>';
        echo '<p>' . $doc->Item[1] . '</p>';
     }

    ces données correspondent a ceci dans le XML:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    </eSummaryResult>
    <DocSum>
    	<Id>23550686</Id>
    		<Item Name="PubDate" Type="Date">2013 Apr 4</Item> Año mes dia
    		<Item Name="Title" Type="String">Images in clinical medicine. Stellate cataract.</Item> Título del artículo
    		<Item Name="Volume" Type="String">368</Item> Volumen
    		<Item Name="Issue" Type="String">14</Item> Fascículo de la revista
    		<Item Name="Pages" Type="String">e18</Item> Páginas Inicio y final  (creo que e=end)
    		</Item>
    </DocSum>
    </eSummaryResult>
    J'arrive pas a extraire le titre par exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    		<Item Name="Title" Type="String">Images in clinical medicine. Stellate cataract.</Item>
    J'ai vue xpath sur un site web mais...j'y arrive pas, quelqu'un pourrais m'expliquer comment pointer sur un champs en particulier?
    D'avance merci

Discussions similaires

  1. récupérer un document XML depuis une URL
    Par ingenieurtunisien dans le forum C#
    Réponses: 12
    Dernier message: 02/10/2010, 17h53
  2. Charger un XML depuis une URL
    Par norwy dans le forum XML
    Réponses: 1
    Dernier message: 19/06/2010, 13h45
  3. Probleme de lecture d'un flux XML depuis une URL
    Par euyeusu dans le forum ASP
    Réponses: 3
    Dernier message: 10/09/2008, 22h01
  4. [SimpleXML] Générer un fichier XML depuis un objet
    Par CactO_o's dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 03/07/2008, 11h17
  5. Recupération de données XML depuis une URL
    Par tonymo dans le forum Format d'échange (XML, JSON...)
    Réponses: 27
    Dernier message: 21/11/2005, 13h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo