/**
  * Encode a contact as XML to be rendered by a stylesheet
  * @todo Check if this exports private/admin hidden values only if allowed.
  * @param Contact $contact
  * @return string XML
  * @global $CONFIG_TAB_ROOT, $country
  */
 function xmlExport($contact)
 {
     global $CONFIG_TAB_ROOT, $country, $addressFormatter;
     $output = '<?xml version="1.0" encoding="utf-8" ?>' . "\n";
     $output .= "<contact>\n";
     $output .= "<id>" . $contact->contact['id'] . "</id>\n";
     $output .= '<fullname>' . htmlspecialchars($contact->contact['namePrefix'] . ' ' . $contact->contact['firstname'] . ' ' . $contact->contact['lastname'] . ' ' . $contact->contact['nameSuffix'], ENT_NOQUOTES, 'UTF-8') . "</fullname>\n";
     $output .= '<name><family>' . htmlspecialchars($contact->contact['lastname'], ENT_NOQUOTES, 'UTF-8') . '</family><given>' . htmlspecialchars($contact->contact['firstname'], ENT_NOQUOTES, 'UTF-8') . '</given><middlename>' . htmlspecialchars($contact->contact['middlename'], ENT_NOQUOTES, 'UTF-8') . '</middlename><prefix>' . htmlspecialchars($contact->contact['namePrefix'], ENT_NOQUOTES, 'UTF-8') . '</prefix><suffix>' . htmlspecialchars($contact->contact['nameSuffix'], ENT_NOQUOTES, 'UTF-8') . "</suffix></name>\n";
     if ($contact->contact['nickname']) {
         $output .= '<nickname>' . $contact->contact['nickname'] . "</nickname>\n";
     }
     //if($contact->contact['birthday'] != '0000-00-00') $output .= 'BDAY:' . ?? . "\n";
     $vg = $contact->getValueGroup('addresses');
     $output .= "<address-list>\n";
     foreach ($vg as $adr) {
         $output .= "<address>\n";
         $output .= "<dbid>" . $adr['refid'] . "</dbid>\n";
         $output .= "<type>" . htmlspecialchars($adr['type'], ENT_NOQUOTES, 'UTF-8') . "</type>\n";
         $output .= '<line1>' . htmlspecialchars($adr['line1'], ENT_NOQUOTES, 'UTF-8') . "</line1>\n";
         $output .= '<line2>' . htmlspecialchars($adr['line2'], ENT_NOQUOTES, 'UTF-8') . "</line2>\n";
         $output .= '<city>' . htmlspecialchars($adr['city'], ENT_NOQUOTES, 'UTF-8') . "</city>\n";
         $output .= '<zip>' . htmlspecialchars($adr['zip'], ENT_NOQUOTES, 'UTF-8') . "</zip>\n";
         $output .= '<state>' . htmlspecialchars($adr['city'], ENT_NOQUOTES, 'UTF-8') . "</state>\n";
         $output .= '<countrycode>' . htmlspecialchars($adr['country'], ENT_NOQUOTES, 'UTF-8') . "</countrycode>\n";
         $output .= '<formatted>' . $addressFormatter->formatAddress($adr) . '</formatted>';
         global $VALUE_GROUP_TYPES_ARRAY;
         foreach ($VALUE_GROUP_TYPES_ARRAY as $t) {
             $output .= "<{$t}-list>\n";
             $vg = $contact->getValueGroup($t, $adr['refid']);
             foreach ($vg as $v) {
                 if ($v['visibility'] != 'visible') {
                     continue;
                 }
                 if ($t != 'date') {
                     $output .= "<{$t}>" . '<label>' . htmlspecialchars($v['label'], ENT_NOQUOTES, 'UTF-8') . '</label><value>' . htmlspecialchars($v['value'], ENT_COMPAT, 'UTF-8') . "</value></{$t}>\n";
                 } else {
                     $output .= "<{$t}>" . '<label>' . htmlspecialchars($v['label'], ENT_NOQUOTES, 'UTF-8') . '</label><value1>' . htmlspecialchars($v['value1'], ENT_NOQUOTES, 'UTF-8') . '</value1><value2>' . htmlspecialchars($v['value2'], ENT_NOQUOTES, 'UTF-8') . '</value2><type>' . htmlspecialchars($v['type'], ENT_NOQUOTES, 'UTF-8') . "</type></{$t}>\n";
                 }
             }
             $output .= "</{$t}-list>\n\n";
         }
         $output .= "</address>\n";
     }
     $output .= "</address-list>\n\n";
     global $VALUE_GROUP_TYPES_ARRAY;
     foreach ($VALUE_GROUP_TYPES_ARRAY as $t) {
         $output .= "<{$t}-list>\n";
         $vg = $contact->getValueGroup($t, null);
         foreach ($vg as $v) {
             if ($v['visibility'] != 'visible') {
                 continue;
             }
             if ($t != 'date') {
                 $output .= "<{$t}>" . '<label>' . htmlspecialchars($v['label'], ENT_NOQUOTES, 'UTF-8') . '</label><value>' . htmlspecialchars($v['value'], ENT_COMPAT, 'UTF-8') . "</value></{$t}>\n";
             } else {
                 $output .= "<{$t}>" . '<label>' . htmlspecialchars($v['label'], ENT_NOQUOTES, 'UTF-8') . '</label><value1>' . htmlspecialchars($v['value1'], ENT_NOQUOTES, 'UTF-8') . '</value1><value2>' . htmlspecialchars($v['value2'], ENT_COMPAT, 'UTF-8') . '</value2><type>' . htmlspecialchars($v['type'], ENT_NOQUOTES, 'UTF-8') . "</type></{$t}>\n";
             }
         }
         $output .= "</{$t}-list>\n\n";
     }
     $ci = new ContactImage($contact);
     $output .= "<pictureURL>" . $ci->uri() . "</pictureURL>\n";
     $output .= "<notes>\n";
     $output .= $contact->contact['notes'];
     // htmlspecialchars does not work here!! (XML processing!)
     $output .= "</notes>\n";
     global $pluginManager;
     $output .= $pluginManager->xmlExport($contact);
     $output .= "</contact>\n";
     $output .= "\n";
     return $output;
 }