File: names.rb

package info (click to toggle)
libdb-ruby 0.6.5-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,612 kB
  • ctags: 3,979
  • sloc: ansic: 13,984; cpp: 8,739; ruby: 7,864; sh: 47; makefile: 8
file content (32 lines) | stat: -rwxr-xr-x 1,003 bytes parent folder | download | duplicates (11)
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
#!/usr/bin/ruby -I../.. -I../../../src

require 'bdbxml'

def names(container, xpath, context)
   puts "Exercising query '#{xpath}'"
   print "Return to continue : "
   STDIN.gets
   results = container.query(xpath, context)
   results.each do |r|
      puts "Document name : #{r.name}"
      puts r
   end
   puts "#{results.size} objects returned for expression '#{xpath}'"
   puts
rescue
   puts "Query #{xpath} failed : #{$!}"
end

options = {'home' => 'env', 'container' => 'name.xml'}

con = BDB::Env.new(options['home'], BDB::INIT_LOMP).
   open_xml(options['container'])

context = BDB::XML::Context.new
context.set_namespace("fruits", "http://groceryItem.dbxml/fruits")
context.set_namespace("vegetables", "http://groceryItem.dbxml/vegetables")
context.set_namespace("desserts", "http://groceryItem.dbxml/desserts");

names(con, "//*[@dbxml:name='ZuluNut.xml']", context)
names(con, "//*[@dbxml:name='TrifleOrange.xml']", context)
names(con, "//*[@dbxml:name='TriCountyProduce.xml']", context)