Menu

[r27]: / branches / parse_tree / parser.php  Maximize  Restore  History

Download this file

42 lines (33 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
if (!extension_loaded('parse_tree')) {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
dl($prefix . 'parse_tree.' . PHP_SHLIB_SUFFIX);
}
require_once 'XML2Array.php';
define('LIBXML_OPTIONS', LIBXML_DTDLOAD | LIBXML_NOENT | LIBXML_DTDATTR | LIBXML_NOCDATA);
$dir = '../../trunk/test/testfiles';
$outputDir = 'output';
$directoryIterator = new DirectoryIterator($dir);
while ($directoryIterator->valid()) {
if ($directoryIterator->isFile()) {
echo $directoryIterator->current(), "\n";
$name = basename($directoryIterator->current(), '.php');
// generate parse tree
$xml1 = new DOMDocument();
$xml1->loadXML(parse_tree_from_file($directoryIterator->getPathname()), LIBXML_OPTIONS);
$xml1->save("$outputDir/$name.xml");
// convert XML to array
$xml2array = new XML2Array($xml1);
file_put_contents("$outputDir/$name.txt", $xml2array);
// transform XML tree to PHP code
/*
$xml2 = new DOMDocument();
$xml2->load('toWrite.xsl', LIBXML_OPTIONS);
$xsl = new XSLTProcessor();
$xsl->importStyleSheet($xml2);
echo $xsl->transformToXML($xml1);
//*/
}
$directoryIterator->next();
}
?>