"); // Open the XML Document $doc = domxml_new_doc('1.0'); $root_elem = $doc->create_element("data_dictionary"); $root_elem = $doc->append_child($root_elem); $data_dictionary = DB_NAME . ".data_dictionary"; print("\nUsing COMS database and default data_dictionary table: $data_dictionary\n\n"); $data_structure = DB_NAME . ".data_structure"; print("\nUsing COMS database and default data_structure table: $data_structure\n\n"); $search_prefix = $_GET['search_prefix']; $data_dictionary = $db->Query("SELECT * FROM data_dictionary WHERE info_name LIKE '%$search_prefix%' ORDER BY info_name ASC"); $dbnames = array(); $tablenames = array(); while ($definition = $db->GetRowAssociative($data_dictionary)) { list($dbname, $tablename, $field) = explode('.', $definition['info_name']); if (in_array($dbname, array_keys($dbnames))) { $dbnode = $dbnames[$dbname]; } else { $dbnode = $doc->create_element("database"); $dbnode = $root_elem->append_child($dbnode); $dbnode->set_attribute("name", $dbname); $dbnames[$dbname] =& $dbnode; $tablenames[$dbname] = array(); } pretty_print_r($tablenames); if (in_array($tablename, array_keys($tablenames[$dbname]))) { $tablenode = $tablenames[$dbname][$tablename]; } else { $tablenode = $doc->create_element("table"); $tablenode = $dbnode->append_child($tablenode); $tablenode->set_attribute("name", $tablename); $tablenames[$dbname][$tablename] =& $tablenode; } $fieldnode = $doc->create_element("field"); $fieldnode->set_attribute("name", $field); foreach ($definition as $attribute => $value) { if ($attribute != 'info_id' && $attribute != 'info_name' && $value) { $fieldnode->set_attribute($attribute, $value); } } $tablenode->append_child($fieldnode); $relationships = $db->Query("SELECT * FROM $data_structure WHERE first_table = '$tablename' AND first_field = '$field'"); while ($relationship = $db->GetRowAssociative($relationships)) { $relnode = $doc->create_element("relationship"); foreach ($relationship as $attribute => $value) { if ($attribute != 'relationship_id' && $value) { $relnode->set_attribute($attribute, $value); } } $relnode = $fieldnode->append_child($relnode); } } $data_lookups = $db->Query("SELECT * FROM data_lookup"); $typenames = array(); if ($db->NumRows($data_lookups)) { $lunode = $doc->create_element("data_lookup"); $lunode = $root_elem->append_child($lunode); } while ($lookup = $db->GetRowAssociative($data_lookups)) { if (in_array($lookup['type'], array_keys($typenames))) { $typenode = $typenames[$lookup['type']]; } else { $typenode = $doc->create_element("type"); $typenode->set_attribute("name", $lookup['type']); $typenode = $lunode->append_child($typenode); $typenames[$lookup['type']] = $typenode; } $optionnode = $doc->create_element("option"); foreach ($lookup as $attribute => $value) { if ($attribute != 'lookup_id' && $value && $attribute != 'type') { $optionnode->set_attribute($attribute, $value); } } $optionnode = $typenode->append_child($optionnode); } ob_end_clean(); if (FOR_REAL) { $doc->dump_file($filename, false, true); } else { header("Content-type: text/xml"); print($doc->dump_mem()); }