php - Parse XML File that is Dyanamically Generated -
i integrating api our monitoring software (prtg) our website , attempting use function generates list of data in xml format. generated needed, url doesn't point existing file.
i tried using "simplexml_load_file" , "simplexml_load_string" , passing url no luck. i've tried use "file_put_contents" first save file, fails since url doesn't point file.
how can made work?
<?php $prtg_url = "http://prtg.domain.net:8080/"; $prtg_user = "username"; $prtg_hash = "passwordhash"; function getsensordata($deviceid) { $sensor_xml_file = $globals['prtg_url'] . "api/table.xml?content=sensors&output=xml&columns=objid,type,device,sensor,status&id=" . $deviceid . "&username=" . $globals['prtg_user'] . "&passhash=" . $globals['prtg_hash']; file_put_contents("sensor.xml", fopen($sensor_xml_file, 'r')); $sensors = simplexml_load_file("sensor.xml"); foreach ($sensors->item $sensor) { $sensor_ping = $sensor->ping; $sensor_id = $sensor->objid; $sensor_type = $sensor->type; $sensor_typeraw = $sensor->type_raw; echo $sensor_ping . "</br>"; echo $sensor_id . "</br>"; echo $sensor_type . "</br>"; echo $sensor_typeraw . "</br>"; } } getsensordata("3401"); ?>
it may file handler. try using simplexml_load_file() url. example:
$url = $globals['prtg_url'] . "api/table.xml?content=sensors&output=xml&columns=objid,type,device,sensor,status&id=" . $deviceid . "&username=" . $globals['prtg_user'] . "&passhash=" . $globals['prtg_hash']); $xml = simplexml_load_file($url);
Comments
Post a Comment