Listing G
<html>
<head></head>
<body>
<?php
// if no data submitted
// display form
if (!$_POST['submit'])
{
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST">
Location:
<br>
<input type="text" name="dir">
<br>
<input type="submit" name="submit" value="Look for XML!">
</form>
<?
}
else
{
// form submitted
// start looking for XML files
// include class file
include ("XML/Statistics.php");
// create object
$xs = new XML_Statistics();
$d = $_POST['dir'];
// check to see if input is a valid directory name
if(is_dir($d))
{
// open directory and iterate over file list
$dh = opendir($d);
while (($f = readdir($dh))!== false)
{
// check to see this is not a directory
// assume XML files have a .xml extension
if (($f !== '.') && ($f !== '..') && (!is_dir($d.'/'.$f)) && (preg_match('/\.xml$/', $f)))
{
// analyze file
$xs->analyzeFile($f);
// print file name
echo "<b>$f:</b><br>";
// count number of elements
echo "Elements: " . $xs->countTag() . "<br>";
// count number of attributes
echo "Attributes: " . $xs->countAttribute() . "<br>";
// count number of PIs
echo "PIs: " . $xs->countPI() . "<br>";
// count number of external entities
echo "External entities: " . $xs->countExternalEntity() . "<br>";
// count number of CDATA blocks
echo "CDATA blocks: " . $xs->countDataChunks() . "<br>";
// get maximum depth
$md = $xs->getMaxDepth();
echo "Maximum depth: $md<br>";
// print number of elements at each level
for ($x=1; $x<=$md; $x++)
{
echo "Elements at depth $x:" . $xs->countTagsInDepth($x) . "<br>";
}
echo "<hr>";
}
else
{
next;
}
}
closedir($dh);
}
// not a valid directory
// print error
else
{
echo "Invalid directory location!";
}
}
?>
</body>
</html>