XML Struktur analysieren / Tiefe von XML-Baum

31.10.2008 | PHP

1. Pear Package XML_Statistics installieren (benötigt Package XML_Parser!)

pear install channel://pear.php.net/XML_statistics-0.1

 

2. Script erstellen siehe: http://articles.techrepublic.com.com/5100-10878_11-5216364.html

z.B.


<?php
// include class file
include ("XML/Statistics.php");

// create object
$xs = new XML_Statistics();

// define XML string
$xmlFile = "CatTree.xml";

// analyze string
$xs->analyzeFile($xmlFile);

// get maximum depth
$md = $xs->getMaxDepth();

echo "<h2>Maximum depth of XML tree is $md </h2>";

// print number of elements at each level
for ($x=1; $x<=$md; $x++)
{
 echo $xs->countTagsInDepth($x) . "  element(s) at level $x <br/>"; 
} 
?>

 

Das Package enthält weitere Beispiel-Skripte.

Analyse

Entwurf

Development

Launch