previousIntroduction (Previous) (Next) XML_Statistics::apiVersionnext

View this page in Last updated: Sun, 18 Oct 2009
English | Brazilian Portuguese | Chinese | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Turkish

Example

Example – Example for the usage of XML_Statistics

Usage example

The following examples shows how XML_Statistics can be used to analyze a document.

Basic example

<?php
require_once "XML/Statistics.php";
$stat = new XML_Statistics(array("ignoreWhitespace" => true));
$result $stat->analyzeFile("example.xml");

if (
$stat->isError($result)) {
    die(
"Error: " $result->getMessage());
}

// total amount of tags:
echo "Total tags: " $stat->countTag() . "<br />";

// count amount of 'title' attribute, in all tags
echo "Occurences of attribute title: " $stat->countAttribute("title") . "<br />";

// count amount of 'title' attribute, only in <section> tags
echo "Occurences of attribute title in tag section: " $stat->countAttribute("title""section") . "<br />";

// count total number of tags in depth 4
echo "Amount of Tags in depth 4: " $stat->countTagsInDepth(4) . "<br />";

echo 
"Occurences of PHP Blocks: " $stat->countPI("PHP") . "<br />";

echo 
"Occurences of external entity 'bar': " $stat->countExternalEntity("bar") . "<br />";

echo 
"Data chunks: " $stat->countDataChunks() . "<br />";

echo 
"Length of all data chunks: " $stat->getCDataLength() . "<br />";
?>
previousIntroduction (Previous) (Next) XML_Statistics::apiVersionnext

Download Documentation Last updated: Sun, 18 Oct 2009
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
There are no user contributed notes for this page.