You are here

function xmlize in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/lib/xmlize.php \xmlize()

Create xml formatted output from an array.

usage:<br> <code> $xml = xmlize($array); </code> See the function {@link traverse_xmlize()} for information about the structure of the array, it's much easier to explain by showing you. Be aware that the array is somewhat tricky. I use xmlize all the time, but still need to use {@link traverse_xmlize()} quite often to show me the structure!

THIS IS A PHP 5 VERSION:

This modified version basically has a new optional parameter to specify an OUTPUT encoding. If not specified, it defaults to UTF-8. I recommend you to read this PHP bug. There you can see how PHP4, PHP5.0.0 and PHP5.0.2 will handle this. {@link http://bugs.php.net/bug.php?id=29711} Ciao, Eloy :-)

@author Hans Anderson

Parameters

array $data The array to be converted:

int $WHITE If set to 1 allows the parser to skip "space" characters in xml document. Default is 1:

string $encoding Specify an OUTPUT encoding. If not specified, it defaults to UTF-8.:

Return value

array

5 calls to xmlize()
hotpot_xml_tree::hotpot_xml_tree in includes/moodle/question/format/hotpot/format.php
qformat_blackboard::readquestions in includes/moodle/question/format/blackboard/format.php
Parses an array of lines into an array of questions, where each item is a question object as defined by readquestion(). Questions are defined as anything between blank lines.
qformat_blackboard_6::readquestions in includes/moodle/question/format/blackboard_6/format.php
Parses an array of lines into an array of questions, where each item is a question object as defined by readquestion(). Questions are defined as anything between blank lines.
qformat_examview::readquestions in includes/moodle/question/format/examview/format.php
Parses an array of lines into an array of questions, where each item is a question object as defined by readquestion(). Questions are defined as anything between blank lines.
qformat_xml::readquestions in includes/moodle/question/format/xml/format.php
parse the array of lines into an array of questions this *could* burn memory - but it won't happen that much so fingers crossed!

File

includes/moodle/lib/xmlize.php, line 46

Code

function xmlize($data, $WHITE = 1, $encoding = 'UTF-8') {
  $data = trim($data);
  $vals = $index = $array = array();
  $parser = xml_parser_create($encoding);
  xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
  xml_parse_into_struct($parser, $data, $vals, $index);
  xml_parser_free($parser);
  $i = 0;
  if (empty($vals)) {

    // XML file is invalid or empty, return false
    return false;
  }
  $tagname = $vals[$i]['tag'];
  if (isset($vals[$i]['attributes'])) {
    $array[$tagname]['@'] = $vals[$i]['attributes'];
  }
  else {
    $array[$tagname]['@'] = array();
  }
  $array[$tagname]["#"] = xml_depth($vals, $i);
  return $array;
}