function tripal_pub_PMID_parse_authorlist

2.x tripal_pub.PMID.inc tripal_pub_PMID_parse_authorlist($xml, &$pub)
3.x tripal_chado.pub_importer_PMID.inc tripal_pub_PMID_parse_authorlist($xml, &$pub)
1.x PMID.inc tripal_pub_PMID_parse_authorlist($xml, &$pub)

Parses the section from the XML returned from PubMed that contains information about the author list for a publication

Parameters

$xml: The XML to parse

$pub: The publication object to which additional details will be added

Related topics

1 call to tripal_pub_PMID_parse_authorlist()
tripal_pub_PMID_parse_article in tripal_pub/includes/importers/tripal_pub.PMID.inc
Parses the section from the XML returned from PubMed that contains information about an article.

File

tripal_pub/includes/importers/tripal_pub.PMID.inc, line 908
This file provides support for importing and parsing of results from the NCBI PubMed database. The functions here are used by both the publication importer setup form and the publication importer.

Code

function tripal_pub_PMID_parse_authorlist($xml, &$pub) {
  $num_authors = 0;

  while ($xml->read()) {
    $element = $xml->name;

    if ($xml->nodeType == XMLReader::END_ELEMENT) {
      // if we're at the </AuthorList> element then we're done with the article...
      if ($element == 'AuthorList') {
        // build the author list before returning
        $authors = '';
        foreach ($pub['Author List'] as $author) {
          if ($author['valid'] == 'N') {
            // skip non-valid entries.  A non-valid entry should have
            // a corresponding corrected entry so we can saftely skip it.
            continue;
          }
          if (array_key_exists('Collective', $author)) {
            $authors .= $author['Collective'] . ', ';
          }
          else {
            $authors .= $author['Surname'] . ' ' . $author['First Initials'] . ', ';
          }
        }
        $authors = substr($authors, 0, -2);
        $pub['Authors'] = $authors;
        return;
      }
      // if we're at the end </Author> element then we're done with the author and we can
      // start a new one.
      if ($element == 'Author') {
        $num_authors++;
      }
    }
    if ($xml->nodeType == XMLReader::ELEMENT) {
      switch ($element) {
        case 'Author':
          $valid = $xml->getAttribute('ValidYN');
          $pub['Author List'][$num_authors]['valid'] = $valid;
          break;
        case 'LastName':
          $xml->read();
          $pub['Author List'][$num_authors]['Surname'] = $xml->value;
          break;
        case 'ForeName':
          $xml->read();
          $pub['Author List'][$num_authors]['Given Name'] = $xml->value;
          break;
        case 'Initials':
          $xml->read();
          $pub['Author List'][$num_authors]['First Initials'] = $xml->value;
          break;
        case 'Suffix':
          $xml->read();
          $pub['Author List'][$num_authors]['Suffix'] = $xml->value;
          break;
        case 'CollectiveName':
          $xml->read();
          $pub['Author List'][$num_authors]['Collective'] = $xml->value;
          break;
        case 'Identifier':
          // according to the specification, this element is not yet used.
          break;
        default:
          break;
      }
    }
  }
}