<?php $target = "http://FREENATS_URL/api.php?mode=xml"; $query=array(); $param=array(); $query[0]="alerts"; $query[1]="node"; $param[1]="bob"; $key=""; // Set Your API Key Here $url=$target."&apikey=".$key; foreach($query as $key => $val) { $url.="&query[".$key."]=".$val; if (isset($param[$key])) $url.="¶m[".$key."]=".$param[$key]; } echo "<html><title>FreeNATS API XML</title>"; echo "<b>".$url."</b><br><br>"; echo "<pre>"; $depth = 0; function startElement($parser, $name, $attrs) { global $depth; for ($i = 0; $i < $depth; $i++) { echo " "; } echo "+ $name "; foreach($attrs as $key => $val) { echo $key."=".$val." "; } echo "\n"; $depth++; } function endElement($parser, $name) { global $depth; $depth--; } function characterData($parser, $data) { $data=trim($data); // remove whitespace if ($data!="") { global $depth; for ($i = 0; $i < $depth; $i++) { echo " "; } echo $data."\n"; } } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = fopen($url, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } fclose($fp); xml_parser_free($xml_parser); echo "</pre>"; ?>