You are here

function biblio_endnote_XML_import in Bibliography Module 6

Import EndNote XML data.

Parameters

$data: the contents of an EndNote XML file passed as one big string

$node: boiler plate information common to all nodes

$version: the EndNote version of the XML file. EndNote uses one format up to version 7 then change to another format in version 8 and greater.

Return value

The node ids of the saved nodes

1 call to biblio_endnote_XML_import()
biblio_import in ./biblio.import.export.inc
Import data from a file and return the node ids created.

File

./biblio.import.export.inc, line 980
Functions that are used to import and export biblio data.

Code

function biblio_endnote_XML_import($xml_file, $taxo_terms = array(), $batch = FALSE, $id = NULL, $ver = 8) {
  global $user, $records, $rec_count, $node, $terms, $batch_proc, $nids, $session_id;
  $batch_proc = $batch;
  $session_id = $id;
  $terms = $taxo_terms;
  $nids = array();
  if (!($fp = fopen($xml_file->filepath, "r"))) {
    drupal_set_message("could not open XML input", 'error');
    return;
  }
  $data = fread($fp, 2048);
  $xml_parser = drupal_xml_parser_create($data);

  // use case-folding so we are sure to find the tag in
  xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
  xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, true);
  module_load_include('inc', 'biblio', 'endnote' . $ver . '_parser');
  xml_set_element_handler($xml_parser, 'en' . $ver . '_startElement', 'en' . $ver . '_endElement');
  xml_set_character_data_handler($xml_parser, 'en' . $ver . '_characterData');
  xml_parse($xml_parser, $data, feof($fp));
  while ($data = fread($fp, 2048)) {

    // $data = fread($fp, 2048);
    set_time_limit(30);
    if (!xml_parse($xml_parser, $data, feof($fp))) {
      drupal_set_message(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)), 'error');
    }
  }
  xml_parser_free($xml_parser);
  fclose($fp);
  return !empty($nids) ? $nids : array();
}