2009-01-09 22:27:31 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
#
|
2009-01-09 22:30:04 +00:00
|
|
|
# usage: validate somefile.xson somefile.bson
|
|
|
|
#
|
|
|
|
# Reads somefile.xson file (XML that describes a Mongo-type document),
|
|
|
|
# converts it into a Ruby OrderedHash, runs that through the BSON
|
|
|
|
# serialization code, and writes the BSON bytes to somefile.bson.
|
2009-01-09 22:27:31 +00:00
|
|
|
#
|
|
|
|
# This script is used by the mongo-qa project
|
|
|
|
# (http://github.com/mongodb/mongo-qa).
|
|
|
|
|
|
|
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
|
|
require 'mongo'
|
|
|
|
require 'mongo/util/xml_to_ruby'
|
|
|
|
|
2009-01-09 22:30:04 +00:00
|
|
|
obj = nil
|
|
|
|
File.open(ARGV[0], 'r') { |f| obj = XMLToRuby.new.xml_to_ruby(f) }
|
2009-01-09 22:27:31 +00:00
|
|
|
bson = BSON.new.serialize(obj).to_a
|
2009-01-09 22:30:04 +00:00
|
|
|
File.open(ARGV[1], 'wb') { |f| bson.each { |b| f.putc(b) } }
|