--- biblio.import.export.inc 2011-04-27 14:40:53.000000000 -0400 +++ biblio.import.export.inc 2011-01-24 14:49:53.000000000 -0500 @@ -75,7 +75,10 @@ 'marc' => t('MARC'), 'ris' => t('RIS'), ); - if (module_exists('biblio_pm')) $import_formats['pubmed'] = t('PubMed ID List'); + if (module_exists('biblio_pm')) { + $import_formats['pubmed'] = t('PubMed ID List'); + $import_formats['pubmed_xml'] = t('PubMed XML'); + } $form['filetype'] = array ( '#type' => 'select', @@ -439,10 +442,13 @@ case 'pubmed' : list($node_ids, $dups) = biblio_pm_biblio_import($import_file, $terms, $batch_proc, $session_id); break; - case 'csv' : // comma separated variable file - // $file_content = @ file_get_contents($import_file->filepath); - // $parsed = biblio_csv_import($file_content, $node_template, $node_array); + case 'pubmed_xml' : + list($node_ids, $dups) = biblio_pm_biblio_xml_import($import_file, $terms, $batch_proc, $session_id); break; + case 'csv' : // comma separated variable file + // $file_content = @ file_get_contents($import_file->filepath); + // $parsed = biblio_csv_import($file_content, $node_template, $node_array); + break; case 'biblio_backup' : // a complete backup of all biblio information $file_content = @ file_get_contents($import_file->filepath); $parsed = biblio_restore($file_content, $node_template, $node_array); --- pubmed/EntrezPubmedArticle.php 2011-04-27 14:40:53.000000000 -0400 +++ pubmed/EntrezPubmedArticle.php 2011-01-25 00:11:04.000000000 -0500 @@ -98,8 +98,12 @@ ); $doi = $this->article->xpath('//ELocationID[@EIdType="doi"]/text()'); + if (empty($doi)) { + $doi = $this->article->xpath('//ArticleId[@IdType="doi"]/text()'); + } if (!empty($doi)) { $this->biblio['biblio_doi'] = (string)$doi[0]; + $doi = ''; } } --- pubmed/biblio_pm.module 2011-04-27 14:40:53.000000000 -0400 +++ pubmed/biblio_pm.module 2011-01-24 21:28:12.000000000 -0500 @@ -120,6 +121,48 @@ return array($nids, $dups); } +function biblio_pm_biblio_xml_import($file, $terms, $batch, $session_id) { + libxml_use_internal_errors(true); + $xml = @simplexml_load_file($file->filepath); + if(empty($xml) || isset($xml->body->pre->ERROR)) { + drupal_set_message("Could not parse file as PubMed XML", 'error'); + return; + } + return _biblio_pm_create_node_from_xml($xml, $batch, $session_id); +} + +function _biblio_pm_create_node_from_xml($result, $batch, $session_id) { + module_load_include('php', 'biblio_pm', 'EntrezPubmedArticle'); + $nids = array(); + $dups = array(); + $node = new stdClass(); + $data = new BiblioEntrezPubmedArticle(); + + foreach ($result->xpath('//PubmedArticle') as $article) { + //$data->setArticle($article); + $node = $data->setArticle($article)->getBiblio(); + if (isset($node)) { + if (!empty($terms)) { + if (!isset($node['taxonomy'])) $node['taxonomy'] = array(); + $node['taxonomy'] = array_merge($terms, $node['taxonomy']); + } + if (! ($dup = biblio_pm_check_md5($node['biblio_pubmed_md5']))) { + $nid = biblio_save_node($node, $batch, $session_id); + if (isset($nid)) { + $nids[] = $nid; + } + } + else { + $dups[] = $dup; + } + $node = null; + } + $start++; + } + + return array($nids, $dups); +} + function biblio_pm_check_pmid($pmid) { return db_result(db_query("SELECT nid FROM {biblio_pubmed} WHERE biblio_pubmed_id = %d", $pmid)); }