/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.ruby

  • Committer: Suren A. Chilingaryan
  • Date: 2009-10-09 04:07:13 UTC
  • Revision ID: csa@dside.dyndns.org-20091009040713-mel06whc852tf2xz
XPath expression optimizations, various fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/ruby
2
2
 
3
3
require 'xml'
 
4
require 'ftools'
4
5
 
5
6
#class Array; def sum; inject( 0 ) { |sum,x| sum+x }; end; end
6
7
 
50
51
end
51
52
 
52
53
def parse(xml, walk)
53
 
    parser = XML::Parser.file(xml)
 
54
#    Does not close a file, complines if many iterations are involved
 
55
#    parser = XML::Parser.file(xml)
 
56
#    doc = parser.parse
 
57
 
 
58
    f = File.new(xml);
 
59
    parser = XML::Parser.io(f)
54
60
    doc = parser.parse
55
61
#    print doc    
 
62
 
56
63
    if (walk)
57
64
#       This is slowest 330 ms
58
65
#       sum = siblings(doc.root)
64
71
#       nodes = doc.find("//*[(number(@*) or number(text())) and (count(../child::*)>3)]")
65
72
#       nodes.each do |node|
66
73
 
67
 
        doc.find("//*[(number(@*) or number(text())) and (count(../child::*)>3)]").each do |node|
 
74
        doc.find("//*[count(child::*)>3]/*[number(@*) or number(text())]").each do |node|
68
75
#           190 ms
69
76
#           sum += calc(node)
70
77
            
111
118
 
112
119
#       print "Sum: #{sum}\n"
113
120
    end
 
121
    f.close
114
122
end
115
123
 
116
124
walk_tree = ENV['walk_tree']