php - Trouble parsing the pubmed central API XML

221

I'm trying to parse the xml output of the PMC API, yet for some reason I get only errors or empty results.. (had no trouble parsing the Pubmed API..)

This is how the XML tools like :

<pmc-articleset>
  <article xmlns:mml="http://www.w3.org/1998/Math/MathML" article-type="research-article">
    <!--...-->
    <front>
      <journal-meta>
        <journal-id journal-id-type="nlm-ta">Cell Death Differ</journal-id>
        <journal-id journal-id-type="iso-abbrev">Cell Death Differ</journal-id>
        <journal-title-group>
          <journal-title>Cell Death and Differentiation</journal-title>
        </journal-title-group>
        <issn pub-type="ppub">1350-9047</issn>
        <issn pub-type="epub">1476-5403</issn>
        <publisher>...</publisher>
      </journal-meta>
      <article-meta>...</article-meta>
    </front>
  </article>
</pmc-articleset>

And this is my code:

$xml = simplexml_load_file($query);
$journal_name = (string)$xml->{'pmc-articleset'}->article->front->{'journal-meta'}->{'journal-title-group'}->{'journal-title'};
echo "Title: ".$journal_name;

Any advice would be appreciated!

782

Answer

Solution:

You are already in thearticle-set element when you start and$article is an element, not a variable, so the$ should be removed.

echo (string)$xml->article->front->{'journal-meta'}->{'journal-title-group'}->{'journal-title'};

https://3v4l.org/GoTu8

People are also looking for solutions to the problem: php - how to get the count of the posts for each month in laravel

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.