$name "; $depth[$parser]++; $lastelem='start'; } function endElement($parser, $name) { global $depth, $lastelem; //echo "/$name "; if ($lastelem=='data') echo "\n"; $depth[$parser]--; } function characterData($parser, $data) { global $depth, $lastelem; $data=trim($data); if ($data) { echo $data; $lastelem='data'; } } // here we go $depth = array(); $lastelem=""; // set up html echo "\nXML parsing for $host:$port\n
\n";

// connect to sc_serv

$sp=fsockopen($host,$port,&$errno,&$errstr,10);
if(!$sp) die("Could not contact $host:$port - $errstr\n");

set_socket_blocking($sp,false);

// send request

fputs($sp,"GET /admin.cgi?pass=$password&mode=viewxml HTTP/1.1\nUser-Agent:Mozilla\n\n");

// fetch response, timeout if it takes > 15s

for($i=0; $i<30; $i++) {
  if(feof($sp)) break; // exit if connection broken
  $sp_data.=fread($sp,31337);
  usleep(500000);
}

// strip HTTP headers so all we have is XML data

$sp_data=ereg_replace("^.*<\?xml ","";

?>