/**
  * set the type definition from an xml structure
  * 
  * @param	string	xml definition
  * @param	string	(byref) variable for failure message
  * @return	boolean setting successful
  */
 public function setXML($a_xml, &$a_failure_message)
 {
     global $lng;
     $this->plugin_object->includeClass('class.ilExternalContentEncodings.php');
     $doc = new DOMDocument('1.0');
     $doc->formatOutput = true;
     if (!@$doc->loadXML($a_xml)) {
         $err = error_get_last();
         $a_failure_message = $err[message];
         return false;
     }
     if (!($interface = $this->getDomChildByName($doc, 'interface'))) {
         $a_failure_message = $this->txt('type_failure_interfaces');
         return false;
     }
     $launch_type = $interface->getAttribute('type');
     switch ($launch_type) {
         case self::LAUNCH_TYPE_EMBED:
         case self::LAUNCH_TYPE_LINK:
         case self::LAUNCH_TYPE_PAGE:
             break;
         default:
             $a_failure_message = sprintf($this->txt('type_failure_launch_type'), $launch_type);
             return false;
     }
     if ($title_element = $this->getDomChildByName($interface, 'title')) {
         $title = $title_element->textContent;
     }
     if ($description_element = $this->getDomChildByName($interface, 'description')) {
         $description = $description_element->textContent;
     }
     if ($template_element = $this->getDomChildByName($interface, 'template')) {
         $template = $template_element->textContent;
     }
     if ($metasource_element = $this->getDomChildByName($interface, 'metasource')) {
         $metasource = $metasource_element->textContent;
     }
     $tmp_fields = array();
     $fields = $interface->getElementsByTagName('field');
     foreach ($fields as $field) {
         $tmp = (object) null;
         // basic properties
         $tmp->field_name = $field->getAttribute('name');
         $tmp->field_type = $field->getAttribute('type');
         // properties for input fields
         $tmp->required = $field->getAttribute('required');
         $tmp->size = $field->getAttribute('size');
         $tmp->rows = $field->getAttribute('rows');
         $tmp->cols = $field->getAttribute('cols');
         $tmp->richtext = $field->getAttribute('richtext');
         $tmp->default = $field->getAttribute('default');
         // appearance of input fields
         $tmp->parentfield = $field->getAttribute('parentfield');
         $tmp->parentvalue = $field->getAttribute('parentvalue');
         $tmp->level = $field->getAttribute('level') ? $field->getAttribute('level') : "object";
         // processing properties
         $tmp->encoding = $field->getAttribute('encoding');
         $tmp->function = $field->getAttribute('function');
         // optional sub elements (field type specific)
         if ($title_element = $this->getDomChildByName($field, 'title')) {
             $tmp->title = $title_element->textContent;
         }
         if ($description_element = $this->getDomChildByName($field, 'description')) {
             $tmp->description = $description_element->textContent;
         }
         if ($template_element = $this->getDomChildByName($field, 'template')) {
             $tmp->template = $template_element->textContent;
         }
         // set options for radio fields
         $tmp->options = array();
         foreach ($field->getElementsByTagName('option') as $option) {
             $opt = (object) null;
             $opt->value = $option->getAttribute('value');
             $opt->title = $this->getDomChildByName($option, 'title')->textContent;
             $opt->description = $this->getDomChildByName($option, 'description')->textContent;
             $tmp->options[$opt->value] = $opt;
         }
         // set parameters for function fields
         $tmp->params = array();
         foreach ($field->getElementsByTagName('param') as $param) {
             $tmp->params[$param->getAttribute('name')] = $param->textContent;
         }
         // checks field name
         if (!$tmp->field_name) {
             $a_failure_message = $this->txt('type_failure_field_name');
             return false;
         }
         // check the field type
         switch ($tmp->field_type) {
             case self::FIELDTYPE_TEMPLATE:
             case self::FIELDTYPE_CALCULATED:
             case self::FIELDTYPE_TEXT:
             case self::FIELDTYPE_TEXTAREA:
             case self::FIELDTYPE_PASSWORD:
             case self::FIELDTYPE_CHECKBOX:
             case self::FIELDTYPE_RADIO:
             case self::FIELDTYPE_HEADER:
             case self::FIELDTYPE_DESCRIPTION:
                 break;
             default:
                 $a_failure_message = sprintf($this->txt('type_failure_field_type'), $tmp->field_type);
                 return false;
         }
         // check the encoding
         if (!ilExternalContentEncodings::_encodingExists($tmp->encoding)) {
             $a_failure_message = sprintf($this->txt('type_failure_encoding'), $tmp->encoding);
             return false;
         }
         // all checks are ok
         $tmp_fields[] = $tmp;
     }
     // set the data if no error occurred
     $this->xml = $a_xml;
     $this->title = $title;
     $this->description = $description;
     $this->launch_type = $launch_type;
     $this->template = $template;
     $this->meta_data_url = $metasource;
     $this->fields = $tmp_fields;
     return true;
 }