lib/happymapper.rb in happymapper-0.2.3 vs lib/happymapper.rb in happymapper-0.2.4
- old
+ new
@@ -1,7 +1,6 @@
dir = File.dirname(__FILE__)
-$:.unshift(dir) unless $:.include?(dir) || $:.include?(File.expand_path(dir))
require 'date'
require 'time'
require 'rubygems'
gem 'libxml-ruby', '= 1.1.3'
@@ -84,18 +83,20 @@
# This is the entry point into the parsing pipeline, so the default
# namespace prefix registered here will propagate down
namespaces = node.namespaces
if namespaces && namespaces.default
- namespaces.default_prefix = DEFAULT_NS
+ already_assigned = namespaces.definitions.detect do |defn|
+ namespaces.default && namespaces.default.href == defn.href && defn.prefix
+ end
+ namespaces.default_prefix = DEFAULT_NS unless already_assigned
namespace ||= DEFAULT_NS
end
xpath = root ? '/' : './/'
xpath += "#{namespace}:" if namespace
xpath += tag_name
- # puts "parse: #{xpath}"
nodes = node.find(xpath)
collection = nodes.collect do |n|
obj = new
@@ -106,11 +107,11 @@
elements.each do |elem|
obj.send("#{elem.method_name}=",
elem.from_xml_node(n, namespace))
end
-
+
obj
end
# per http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/Document.html#M000354
nodes = nil
@@ -122,8 +123,8 @@
end
end
end
end
-require 'happymapper/item'
-require 'happymapper/attribute'
-require 'happymapper/element'
+require File.join(dir, 'happymapper/item')
+require File.join(dir, 'happymapper/attribute')
+require File.join(dir, 'happymapper/element')