function qformat_xml::getpath in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/question/format/xml/format.php \qformat_xml::getpath()
 
return the value of a node, given a path to the node if it doesn't exist return the default value
Parameters
array xml data to read:
array path path to node expressed as array :
mixed default :
bool istext process as text:
string error if set value must exist, return false and issue message if not:
Return value
mixed value
9 calls to qformat_xml::getpath()
- qformat_xml::import_answer in includes/
moodle/ question/ format/ xml/ format.php  - import the common parts of a single answer
 - qformat_xml::import_essay in includes/
moodle/ question/ format/ xml/ format.php  - import essay type question
 - qformat_xml::import_headers in includes/
moodle/ question/ format/ xml/ format.php  - import parts of question common to all types
 - qformat_xml::import_matching in includes/
moodle/ question/ format/ xml/ format.php  - import matching type question
 - qformat_xml::import_multianswer in includes/
moodle/ question/ format/ xml/ format.php  - import cloze type question
 
File
- includes/
moodle/ question/ format/ xml/ format.php, line 96  
Class
Code
function getpath($xml, $path, $default, $istext = false, $error = '') {
  foreach ($path as $index) {
    if (!isset($xml[$index])) {
      if (!empty($error)) {
        $this
          ->error($error);
        return false;
      }
      else {
        return $default;
      }
    }
    else {
      $xml = $xml[$index];
    }
  }
  if ($istext) {
    if (!is_string($xml)) {
      $this
        ->error(get_string('invalidxml', 'qformat_xml'));
    }
    $xml = addslashes(trim($xml));
  }
  return $xml;
}