public function getElementsAsDOM()
 {
     $t_list = new ca_lists();
     $vo_elements = $this->opo_dom->createElement("elementSets");
     $qr_elements = $this->opo_db->query("SELECT * FROM ca_metadata_elements WHERE parent_id IS NULL ORDER BY element_id");
     $t_element = new ca_metadata_elements();
     while ($qr_elements->nextRow()) {
         $vo_element = $this->opo_dom->createElement("metadataElement");
         $vo_element->setAttribute("code", $this->makeIDNO($qr_elements->get("element_code")));
         $vo_element->setAttribute("datatype", ca_metadata_elements::getAttributeNameForTypeCode($qr_elements->get("datatype")));
         if ($qr_elements->get("list_id")) {
             $t_list->load($qr_elements->get("list_id"));
             $vo_element->setAttribute("list", $t_list->get("list_code"));
         }
         $vo_labels = $this->opo_dom->createElement("labels");
         $qr_element_labels = $this->opo_db->query("SELECT * FROM ca_metadata_element_labels WHERE element_id=?", $qr_elements->get("element_id"));
         while ($qr_element_labels->nextRow()) {
             $vo_label = $this->opo_dom->createElement("label");
             $vo_label->setAttribute("locale", $this->opt_locale->localeIDToCode($qr_element_labels->get("locale_id")));
             $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($qr_element_labels->get("name"))));
             if (strlen(trim($qr_element_labels->get("description"))) > 0) {
                 $vo_label->appendChild($this->opo_dom->createElement("description", caEscapeForXML($qr_element_labels->get("description"))));
             }
             $vo_labels->appendChild($vo_label);
         }
         $vo_element->appendChild($vo_labels);
         $t_element->load($qr_elements->get("element_id"));
         $va_settings = $t_element->getSettings();
         $va_available_settings = $t_element->getAvailableSettings();
         if (is_array($va_settings)) {
             $vo_settings = $this->opo_dom->createElement("settings");
             $vb_append_settings_element = false;
             foreach ($t_element->getSettings() as $vs_setting => $vs_value) {
                 if ($t_element->isValidSetting($vs_setting) && $vs_value != $va_available_settings[$vs_setting]["default"]) {
                     $vo_setting = $this->opo_dom->createElement("setting", $vs_value);
                     $vo_setting->setAttribute("name", $vs_setting);
                     $vo_settings->appendChild($vo_setting);
                     $vb_append_settings_element = true;
                 }
             }
             if ($vb_append_settings_element) {
                 $vo_element->appendChild($vo_settings);
             }
         }
         $vo_sub_elements = $this->getElementAsDOM($qr_elements->get("element_id"));
         if ($vo_sub_elements) {
             $vo_element->appendChild($vo_sub_elements);
         }
         $vo_restrictions = $this->opo_dom->createElement("typeRestrictions");
         foreach ($t_element->getTypeRestrictions() as $va_restriction) {
             /** @var ca_metadata_type_restrictions $t_restriction */
             $t_restriction = new ca_metadata_type_restrictions($va_restriction["restriction_id"]);
             $vs_table_name = $this->opo_dm->getTableName($t_restriction->get("table_num"));
             if (!(strlen($vs_table_name) > 0)) {
                 continue;
             }
             // there could be lingering restrictions for tables that have since been removed. don't export those.
             $vo_restriction = $this->opo_dom->createElement("restriction");
             $vo_table = $this->opo_dom->createElement("table", $vs_table_name);
             $vo_restriction->appendChild($vo_table);
             if ($t_restriction->get("type_id")) {
                 /** @var BaseRelationshipModel $t_instance */
                 $t_instance = $this->opo_dm->getInstanceByTableNum($t_restriction->get("table_num"));
                 $vs_type_code = $t_instance->getTypeListCode();
                 $va_item = $t_list->getItemFromListByItemID($vs_type_code, $t_restriction->get("type_id"));
                 $vo_type = $this->opo_dom->createElement("type", $va_item["idno"]);
                 $vo_restriction->appendChild($vo_type);
             }
             if (isset($va_restriction['include_subtypes']) && (bool) $va_restriction['include_subtypes']) {
                 $vo_include_subtypes = $this->opo_dom->createElement('includeSubtypes', '1');
                 $vo_restriction->appendChild($vo_include_subtypes);
             }
             if (is_array($va_restriction_settings = $t_restriction->getSettings())) {
                 $vo_settings = $this->opo_dom->createElement("settings");
                 foreach ($va_restriction_settings as $vs_setting => $vs_value) {
                     $vo_setting = $this->opo_dom->createElement("setting", $vs_value);
                     $vo_setting->setAttribute("name", $vs_setting);
                     $vo_settings->appendChild($vo_setting);
                 }
                 $vo_restriction->appendChild($vo_settings);
             }
             $vo_restrictions->appendChild($vo_restriction);
         }
         $vo_element->appendChild($vo_restrictions);
         $vo_elements->appendChild($vo_element);
     }
     return $vo_elements;
 }