xpath performance with merged Nokogiri::XML::NodeSet

Licedache

New Member
I am getting data from a webservices, 100 per Page. My script joins these pages to a Nokogiri::XML::Nodeset. Searching the nodeset via XPath is extremely slow.Example code:\[code\]rows = [](1..500).to_a.each_slice(100) { |slice| rows << Nokogiri::XML::Builder.new { |xml| xml.root { xml.rows { slice.each { |num| xml.row { xml.NUMBER { xml.text num } } } } } }.doc.at('/root/rows')}rows = rows.map { |a| a.children }.inject(:+)\[/code\]The resulting NodeSet contains nodes from 5 documents. This seems to be a problem.\[code\]rows.map { |r| r.document.object_id }.uniq => [21430080, 21732480, 21901100, 38743080, 40472240]\[/code\]The following code runs about 10 seconds. With a non-merged nodeset this is done within a blink of an eye\[code\](1..500).to_a.sample(100).each do |sample| rows.at('//row[./NUMBER="%d"]' % sample)end\[/code\]Does somebody has an solution to merge the Nodesets a better way or merge the documents?I would like to keep the behaviour of only one nodeset, as this data is practically one big nodeset, which was splitted by the webservice for technical reasons.Thanks,krissi
 
Back
Top