You are here

function NodeExportXmlDecoder::decode in Node export 7.3

Same name and namespace in other branches
  1. 6.3 modules/node_export_xml/node_export_xml.module \NodeExportXmlDecoder::decode()

File

formats/xml.inc, line 114
The Node export XML format handler.

Class

NodeExportXmlDecoder
Class for parsing Node export XML.

Code

function decode($code_string) {
  $parser = xml_parser_create();
  xml_set_element_handler($parser, array(
    &$this,
    'start_handler',
  ), array(
    &$this,
    'end_handler',
  ));
  xml_set_character_data_handler($parser, array(
    &$this,
    'data_handler',
  ));
  $this->stack = array(
    array(
      'name' => 'node_export',
      'attributes' => array(),
      'children' => array(),
      'data' => '',
    ),
  );
  if (!xml_parse($parser, $code_string)) {
    $errors[] = "Node export XML import was unsuccessful, error details follow.  No nodes imported.";
    $line = xml_get_current_line_number($parser);
    $column = xml_get_current_column_number($parser);
    $error = xml_error_string(xml_get_error_code($parser));
    $errors[] = "Line " . $line . ", Column " . $column . ": " . $error;
    $lines = explode("\n", $code_string, $line + 1);
    $errors[] = "<pre>" . htmlspecialchars($lines[$line - 1]) . "</pre>";
    xml_parser_free($parser);
    return array(
      'success' => FALSE,
      'output' => $errors,
    );
  }
  xml_parser_free($parser);
  $tmp = $this
    ->build($this->stack[0]);
  if (count($tmp) == 1) {
    $this->output = array_pop($tmp);
  }
  else {
    $this->output = array();
  }
  unset($this->stack);
  return $this->output;
}