/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to parse/scripts/libxml.php

  • Committer: Suren A. Chilingaryan
  • Date: 2009-10-02 01:16:02 UTC
  • Revision ID: csa@dside.dyndns.org-20091002011602-ut1jl0go12npun6y
DOM walking for all Libxml bindings: ruby, python, perl, php, lisp

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/php
2
2
<?
3
 
function parse($xml) {
 
3
function parse($xml, $walk_tree) {
4
4
    $doc = new DOMDocument();
5
5
    $doc->load($xml);
 
6
    if ($walk_tree) {
 
7
        $sum = 0;
 
8
        $xp = new DOMXPath($doc);
 
9
        $nodes = $xp->query("//*[(number(@*) or number(text())) and (count(../child::*)>3)]");
 
10
        foreach ($nodes as $node) {
 
11
            $child = $node->firstChild;
 
12
            if (($child)&&($child instanceof DOMText)) {
 
13
                $value = &$child->textContent;
 
14
                if (is_numeric($value)) {
 
15
                    $sum += $value;
 
16
                    continue;
 
17
                }
 
18
            }
 
19
            if ($node->attributes) {
 
20
                foreach ($node->attributes as $attr) {
 
21
                    if (is_numeric($attr->value)) {
 
22
                        $sum += $attr->value;
 
23
                        break;
 
24
                    }
 
25
                }
 
26
            }
 
27
        }
 
28
#       echo "Sum: {$sum}\n";
 
29
    }
6
30
    //echo $doc->saveXML();
7
31
    unset($doc);
8
32
}
9
33
 
10
34
$argv = $_SERVER['argv'];
 
35
$walk_tree = $_SERVER['walk_tree'];
11
36
 
12
37
if (sizeof($argv) > 1)
13
38
    $iterations = $argv[1];
19
44
else
20
45
    $filename = create_function('$i', 'return "../xml.tmp/{$i}.xml";');
21
46
 
22
 
parse($filename(0));
 
47
parse($filename(0), $walk_tree);
23
48
 
24
49
for ($i=1;$i<=$iterations;$i++) {
25
 
    parse($filename($i));
 
50
    parse($filename($i), $walk_tree);
26
51
}
27
52
?>
 
 
b'\\ No newline at end of file'