/**
  * exportReqSpecToXML
  * create XML string with following req spec data
  *  - basic data (title, scope)
  *  - custom fields values
  *  - children: can be other req spec  or requirements (tree leaves)
  *
  * Developed using exportTestSuiteDataToXML() as model
  *
  * @internal revision
  * 20100320 - franciscom - added TYPE
  * 20091122 - franciscom - added doc id management  
  */
 function exportReqSpecToXML($id, $tproject_id, $optExport = array())
 {
     static $req_mgr;
     // manage missing keys
     $optionsForExport = array('RECURSIVE' => true);
     foreach ($optionsForExport as $key => $value) {
         $optionsForExport[$key] = isset($optExport[$key]) ? $optExport[$key] : $value;
     }
     $cfXML = null;
     $xmlData = null;
     if ($optionsForExport['RECURSIVE']) {
         $cfXML = $this->customFieldValuesAsXML($id, $tproject_id);
         $containerData = $this->get_by_id($id);
         $xmlData = "<req_spec title=\"" . htmlspecialchars($containerData['title']) . '" ' . " doc_id=\"" . htmlspecialchars($containerData['doc_id']) . '" >' . "\n<type><![CDATA[{$containerData['type']}]]></type>\n" . "\n<node_order><![CDATA[{$containerData['node_order']}]]></node_order>\n" . "\n<total_req><![CDATA[{$containerData['total_req']}]]></total_req>\n" . "<scope>\n<![CDATA[{$containerData['scope']}]]>\n</scope>\n{$cfXML}";
     }
     $req_spec = $this->getReqTree($id);
     $childNodes = isset($req_spec['childNodes']) ? $req_spec['childNodes'] : null;
     if (!is_null($childNodes)) {
         $loop_qty = sizeof($childNodes);
         for ($idx = 0; $idx < $loop_qty; $idx++) {
             $cNode = $childNodes[$idx];
             $nTable = $cNode['node_table'];
             if ($optionsForExport['RECURSIVE'] && $cNode['node_table'] == 'req_specs') {
                 $xmlData .= $this->exportReqSpecToXML($cNode['id'], $tproject_id, $optionsForExport);
             } else {
                 if ($cNode['node_table'] == 'requirements') {
                     if (is_null($req_mgr)) {
                         $req_mgr = new requirement_mgr($this->db);
                     }
                     $xmlData .= $req_mgr->exportReqToXML($cNode['id'], $tproject_id);
                 }
             }
         }
     }
     if ($optionsForExport['RECURSIVE']) {
         $xmlData .= "</req_spec>";
     }
     return $xmlData;
 }