function toXML(&$writer)
 {
     $writer->xmlStartTag('MetaData');
     // General
     if (is_object($gen =& $this->getGeneral())) {
         $gen->setExportMode($this->getExportMode());
         $gen->toXML($writer);
     } else {
         // Defaults
         include_once 'Services/MetaData/classes/class.ilMDGeneral.php';
         $gen = new ilMDGeneral($this->getRBACId(), $this->getObjId(), $this->getObjType());
         // added type, alex, 31 Oct 2007
         $gen->setExportMode($this->getExportMode());
         $gen->toXML($writer);
     }
     // Lifecycle
     if (is_object($lif =& $this->getLifecycle())) {
         $lif->toXML($writer);
     }
     // Meta-Metadata
     if (is_object($met =& $this->getMetaMetadata())) {
         $met->toXML($writer);
     }
     // Technical
     if (is_object($tec =& $this->getTechnical())) {
         $tec->toXML($writer);
     }
     // Educational
     if (is_object($edu =& $this->getEducational())) {
         $edu->toXML($writer);
     }
     // Rights
     if (is_object($rig =& $this->getRights())) {
         $rig->toXML($writer);
     }
     // Relations
     foreach ($this->getRelationIds() as $id) {
         $rel =& $this->getRelation($id);
         $rel->toXML($writer);
     }
     // Annotations
     foreach ($this->getAnnotationIds() as $id) {
         $ann =& $this->getAnnotation($id);
         $ann->toXML($writer);
     }
     // Classification
     foreach ($this->getClassificationIds() as $id) {
         $cla =& $this->getClassification($id);
         $cla->toXML($writer);
     }
     $writer->xmlEndTag('MetaData');
 }