function __buildPageXML($page, &$database)
 {
     $oPage = new XMLElement('page');
     $oPage->setAttribute('handle', $page['handle']);
     $oPage->appendChild(new XMLElement('name', General::sanitize($page['title'])));
     $types = $database->fetchCol('type', "SELECT `type` FROM `tbl_pages_types` WHERE `page_id` = '" . $page['id'] . "'");
     if (is_array($types) && !empty($types)) {
         $xTypes = new XMLElement('types');
         foreach ($types as $type) {
             $xTypes->appendChild(new XMLElement('type', $type));
         }
         $oPage->appendChild($xTypes);
     }
     if ($children = $database->fetch("SELECT * FROM `tbl_pages` WHERE `parent` = '" . $page['id'] . "' ORDER BY `sortorder` ASC")) {
         foreach ($children as $c) {
             $oPage->appendChild(__buildPageXML($c, $database));
         }
     }
     return $oPage;
 }
 function __buildPageXML($page, $page_types)
 {
     $oPage = new XMLElement('page');
     $oPage->setAttribute('handle', $page['handle']);
     $oPage->setAttribute('id', $page['id']);
     $oPage->appendChild(new XMLElement('name', General::sanitize($page['title'])));
     if (in_array($page['id'], array_keys($page_types))) {
         $xTypes = new XMLElement('types');
         foreach ($page_types[$page['id']] as $type) {
             $xTypes->appendChild(new XMLElement('type', $type));
         }
         $oPage->appendChild($xTypes);
     }
     if ($children = Symphony::Database()->fetch("SELECT * FROM `tbl_pages` WHERE `parent` = '" . $page['id'] . "' ORDER BY `sortorder` ASC")) {
         foreach ($children as $c) {
             $oPage->appendChild(__buildPageXML($c, $page_types));
         }
     }
     return $oPage;
 }