function build_xml($arr, $endMark = '', $depth = 0) { global $XMLContent; global $CNTag; $check = true; if ($arr[0]) { $check = false; } foreach ($arr as $k => $v) { if (is_array($v)) { if ($v[0]) { build_xml($v, $k, $depth + 1); continue; } else { if (is_numeric($k)) { $XMLContent .= str_repeat(' ', $depth) . '<' . $CNTag[$endMark] . '> '; build_xml($v, $endMark, $depth + 1); continue; } else { $XMLContent .= '<' . $CNTag[$k] . '> '; build_xml($v, $k, $depth + 1); continue; } continue; } continue; } else { if (is_numeric($v) or !$v) { $contents = $v; } else { $contents = '<![CDATA[' . $v . ']]>'; } $XMLContent .= str_repeat(' ', $depth) . '<' . $CNTag[$k] . '>' . $contents . '</' . $CNTag[$k] . '> '; continue; } } if ($endMark and $check) { $XMLContent .= str_repeat(' ', $depth - 1) . '</' . $CNTag[$endMark] . '> '; } }
/** * @param $dbname Name of the database * @return string An XML string containing all POIs */ function fetch_all_pois($dbname) { //connect to the created SQLite database $db = new SQLite3($dbname); //read all the table records from the database $records = $db->query("SELECT * FROM POIsM;"); $pois = build_xml($records, "en"); $db->close(); // return $records; return $pois; }