loadXML($HTTP_RAW_POST_DATA); if (!$dom->relaxNGValidate ( 'watch.rng')) { die("unvalid document"); } $xml = simplexml_import_dom($dom); foreach ($xml->children() as $element) { $element['escaped'] = sqlite_escape_string(trim($element)); } //echo $xml->asXML(); $query = $db->query( "SELECT symbol from watches where symbol='". $xml->symbol['escaped']. "'", SQLITE_NUM); $req = ""; if ($query->fetch()) { $req="update watches set "; $req .= "tag='".$xml->tag['escaped']."', "; $req .= "title='".$xml->title['escaped']."', "; $req .= "description='".$xml->description['escaped']."' "; $req .= "where symbol='".$xml->symbol['escaped']."'"; } else { $req="insert into watches (symbol, tag, title, description) values ("; $req .= "'".$xml->symbol['escaped']."', "; $req .= "'".$xml->tag['escaped']."', "; $req .= "'".$xml->title['escaped']."', "; $req .= "'".$xml->description['escaped']."')"; } //echo $req; $db->queryExec($req); echo ""; } function displayOne($row) { $xml = simplexml_load_string("<description/></watch>"); $xml->symbol=$row['symbol']; $xml->tag=$row['tag']; $xml->title=$row['title']; $xml->description=$row['description']; printAsFragment($xml); } function readOne() { $db=openDb(); $query = queryOneWatch($db); if ($row = $query->fetch(SQLITE_ASSOC)) { displayOne($row); } else { $xml = simplexml_load_string("<watch/>"); printAsFragment($xml); } } function listAll() { $db=openDb(); echo "<watches>"; $query = queryAllWatches($db); while ($row = $query->fetch(SQLITE_ASSOC)) { displayOne($row); } echo "</watches>"; } header("Cache-Control: max-age=60"); header("Content-type: application/xml"); echo '<?xml version="1.0" encoding="utf-8"?>'; if (strlen($HTTP_RAW_POST_DATA)>0) { write(); } else if ($_GET['name']) { readOne(); } else { listAll(); } ?>