xpath and SimpleXML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I'm using PHP5.0.2 and SimpleXML to build a systems monitoring application. 
I'm pulling data from Win server perfmon logs, using MS Log Parser to output 
into XML, then a PHP command line script (run every x minutes) using 
SimpleXML to parse, and then to make decisions.

The issue I am having trouble with is that the output of the perfmon logs 
(XML output with Log Parser) is like this:

<!DOCTYPE ROOT (View Source for full doctype...)>
- <ROOT DATE_CREATED="2004-10-07 02:28:15" CREATED_BY="Microsoft Log Parser 
V2.1">
- <ROW>
<Filename>c:\perflogs\Basic_Counters_10070839.csv</Filename>
<RowNumber>2</RowNumber>
<__PDH-CSV_4.0___New_Zealand_Daylight_Time__-780__>"10/07/2004 
08:39:02.343"</__PDH-CSV_4.0___New_Zealand_Daylight_Time__-780__>
<__LogicalDisk_C_____Disk_Time_>"8.0669532236989439e-006"</__LogicalDisk_C_____Disk_Time_>
<__LogicalDisk_C_____Free_Space_>"72.189023431357128"</__LogicalDisk_C_____Free_Space_>


I want to be able to say, for example, if LogicalDiskC space < 100MB then do 
something.

So, using xpath, I have constructed the following function. The problem is 
the quotes "" around the number. xpath is treating it as a string, I 
believe.

// eg $var1 = __Memory_Available_MBytes_, $var2 = 100, $anything is the 
simplexml object
function query_greater_than($var1, $var2, $anything) {
// bring in the output, so we can concatenate it.
$result = $anything->xpath("//ROW[$var1 > $var2]");
// Does the query return any data?
if (count($result)>0) {
echo "outputting data";
while(list( , $node) = each($result)) {
// taking each output from xpath, coverting it to xml, and concatenating in 
x.
$x.=$node->asXML();
}
}
}

Is there an easy way to format the input data (ie the $anything object) to 
strip off the slashes, and make into an integer?

I have tried to use the number() function in xpath, however can't get the 
right syntax.

I have tried using str_replace("\"", "", $var2) on the whole xml input file.

I've also tried using
$filename="basiccounters1.xml";
$a=file_get_contents($filename);
echo $a;
//$b=str_replace("perflogs", "hello", $a);
$b = ereg_replace("perflogs", "hello", $a);
echo "b is $b";

Both ways gave very strange results, possibly as the input file 
basiccounters1.xml was 6MB, and I was loading it into a string.

Kind regards

Dave.

PS I'm using these technologies (ie PHP) over other perhaps more suitable 
one (eg PERL) as I'm more comfortable in PHP.

PPS There is more code not shown.. I've got the rest of the app working (ie 
using xpath 'contains' ie string functions), but number functions are a 
problem. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux