original_string: protected function write_xml($element, array $data, array $attribs = array(), $parent = '/') {
  
          if (!$this->has_xml_writer()) {
              throw new moodle1_convert_exception('write_xml_without_writer');
          }
  
          $mypath    = $parent . $element;
          $myattribs = array();
  
          // detect properties that should be rendered as element's attributes instead of children
          foreach ($data as $name => $value) {
              if (!is_array($value)) {
                  if (in_array($mypath . '/' . $name, $attribs)) {
                      $myattribs[$name] = $value;
                      unset($data[$name]);
                  }
              }
          }
  
          // reorder the $data so that all sub-branches are at the end (needed by our parser)
          $leaves   = array();
          $branches = array();
          foreach ($data as $name => $value) {
              if (is_array($value)) {
                  $branches[$name] = $value;
              } else {
                  $leaves[$name] = $value;
              }
          }
          $data = array_merge($leaves, $branches);
  
          $this->xmlwriter->begin_tag($element, $myattribs);
  
          foreach ($data as $name => $value) {
              if (is_array($value)) {
                  // recursively call self
                  $this->write_xml($name, $value, $attribs, $mypath.'/');
              } else {
                  $this->xmlwriter->full_tag($name, $value);
              }
          }
  
          $this->xmlwriter->end_tag($element);
      }
code: protected function write_xml($element, array $data, array $attribs = array(), $parent = '/') {
  
          if (!$this->has_xml_writer()) {
              throw new moodle1_convert_exception('write_xml_without_writer');
          }
  
          $mypath    = $parent . $element;
          $myattribs = array();
  
          // detect properties that should be rendered as element's attributes instead of children
          foreach ($data as $name => $value) {
              if (!is_array($value)) {
                  if (in_array($mypath . '/' . $name, $attribs)) {
                      $myattribs[$name] = $value;
                      unset($data[$name]);
                  }
              }
          }
  
          // reorder the $data so that all sub-branches are at the end (needed by our parser)
          $leaves   = array();
          $branches = array();
          foreach ($data as $name => $value) {
              if (is_array($value)) {
                  $branches[$name] = $value;
              } else {
                  $leaves[$name] = $value;
              }
          }
          $data = array_merge($leaves, $branches);
  
          $this->xmlwriter->begin_tag($element, $myattribs);
  
          foreach ($data as $name => $value) {
              if (is_array($value)) {
                  // recursively call self
                  $this->write_xml($name, $value, $attribs, $mypath.'/');
              } else {
                  $this->xmlwriter->full_tag($name, $value);
              }
          }
  
          $this->xmlwriter->end_tag($element);
      }
code_tokens: protected function write_xml ( $ element , array $ data , array $ attribs = array ( ) , $ parent = '/' ) { if ( ! $ this -> has_xml_writer ( ) ) { throw new moodle1_convert_exception ( 'write_xml_without_writer' ) ; } $ mypath = $ parent . $ element ; $ myattribs = array ( ) ; // detect properties that should be rendered as element's attributes instead of children foreach ( $ data as $ name => $ value ) { if ( ! is_array ( $ value ) ) { if ( in_array ( $ mypath . '/' . $ name , $ attribs ) ) { $ myattribs [ $ name ] = $ value ; unset ( $ data [ $ name ] ) ; } } } // reorder the $data so that all sub-branches are at the end (needed by our parser) $ leaves = array ( ) ; $ branches = array ( ) ; foreach ( $ data as $ name => $ value ) { if ( is_array ( $ value ) ) { $ branches [ $ name ] = $ value ; } else { $ leaves [ $ name ] = $ value ; } } $ data = array_merge ( $ leaves , $ branches ) ; $ this -> xmlwriter -> begin_tag ( $ element , $ myattribs ) ; foreach ( $ data as $ name => $ value ) { if ( is_array ( $ value ) ) { // recursively call self $ this -> write_xml ( $ name , $ value , $ attribs , $ mypath . '/' ) ; } else { $ this -> xmlwriter -> full_tag ( $ name , $ value ) ; } } $ this -> xmlwriter -> end_tag ( $ element ) ; }
docstring: Writes the given XML tree data into the currently opened file
  
  @param string $element the name of the root element of the tree
  @param array $data the associative array of data to write
  @param array $attribs list of additional fields written as attributes instead of nested elements
  @param string $parent used internally during the recursion, do not set yourself
docstring_tokens: Writes the given XML tree data into the currently opened file