You are here

biblio_xml.inc in Bibliography Module 7

Same filename and directory in other branches
  1. 6.2 includes/biblio_xml.inc

Copyright (C) 2006-2011 Ron Jerome.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. **************************************************************************

File

includes/biblio_xml.inc
View source
<?php

/**
 * @file
 * Copyright (C) 2006-2011  Ron Jerome.
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 ****************************************************************************/

/**
 * @param $result
 *
 * @return
 */
function biblio_xml_export($result) {
  set_time_limit(300);
  $nid = 0;
  $dom = new DOMDocument('1.0', 'UTF-8');
  $biblio_collection = $dom
    ->appendChild(new DOMElement('biblio_collection'));
  $biblio_collection
    ->setAttribute("Schema", "6010");
  $comment = $biblio_collection
    ->appendChild(new DOMComment('Generated by the Biblio module from Drupal (http://drupal.org/project/biblio)'));
  $db_result = db_query("SELECT nr.nid, nr.vid  FROM {node_revision} nr join node n on nr.nid=n.nid where n.type='biblio' order by nr.nid, nr.vid");
  while ($n = db_fetch_object($db_result)) {
    $node = node_load($n->nid, $n->vid);
    if ($n->nid == $nid) {
      $revision = $domnode
        ->appendChild(new DOMElement('revision'));
      $node = (array) $node;
      AtoX($node, $dom, $revision);
    }
    else {
      $domnode = $biblio_collection
        ->appendChild(new DOMElement('node'));
      $node = (array) $node;
      AtoX($node, $dom, $domnode);
    }
    $nid = $n->nid;
  }
  return $dom
    ->saveXML();
}

/**
 *
 */
function AtoX($array, $DOM = NULL, $root = NULL) {
  foreach ($array as $key => $value) {
    if ($key == 'biblio_contributors') {
      $name = 'contributor';
    }
    if (is_numeric($key)) {
      $key = 'c_' . $key;
    }
    if (is_array($value) && count($value)) {
      $subroot = $root
        ->appendChild($DOM
        ->createElement($key));
      AtoX($value, $DOM, $subroot);
    }
    else {
      if (!empty($value)) {
        $root
          ->appendChild($DOM
          ->createElement($key, htmlspecialchars($value, ENT_QUOTES)));
      }
    }
  }
  return $DOM;
}

Functions