3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * XML format importer class from memory storage
24 * @copyright 2008 Andrei Bautu
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die();
31 * XML format importer class from memory storage (i.e. string).
33 class string_xml_database_importer
extends xml_database_importer
{
34 /** String with XML data. */
40 * @param string data - string with XML data
41 * @param moodle_database $mdb Connection to the target database
42 * @see xml_database_importer::__construct()
43 * @param boolean $check_schema - whether or not to check that XML database
44 * @see xml_database_importer::__construct()
46 public function __construct($data, moodle_database
$mdb, $check_schema=true) {
47 parent
::__construct($mdb, $check_schema);
52 * Common import method: it creates the parser, feeds the XML parser with
53 * data, releases the parser.
56 public function import_database() {
57 $parser = $this->get_parser();
58 if (!xml_parse($parser, $this->data
, true)) {
59 throw new dbtransfer_exception('malformedxmlexception');
61 xml_parser_free($parser);