diff --git a/lib/multi_xml/parsers/libxml.rb b/lib/multi_xml/parsers/libxml.rb index 308ed8e..406c0b8 100644 --- a/lib/multi_xml/parsers/libxml.rb +++ b/lib/multi_xml/parsers/libxml.rb @@ -35,14 +35,12 @@ def to_hash end module Node #:nodoc: - CONTENT_ROOT = '__content__'.freeze unless defined?(CONTENT_ROOT) - # Convert XML document to hash # # hash:: # Hash to merge the converted element into. def to_hash(hash={}) - node_hash = {CONTENT_ROOT => ''} + node_hash = {MultiXml::CONTENT_ROOT => ''} # Insert node hash into parent hash correctly. case hash[name] @@ -56,13 +54,13 @@ def to_hash(hash={}) if c.element? c.to_hash(node_hash) elsif c.text? || c.cdata? - node_hash[CONTENT_ROOT] << c.content + node_hash[MultiXml::CONTENT_ROOT] << c.content end end # Remove content node if it is empty - if node_hash[CONTENT_ROOT].strip.empty? - node_hash.delete(CONTENT_ROOT) + if node_hash[MultiXml::CONTENT_ROOT].strip.empty? + node_hash.delete(MultiXml::CONTENT_ROOT) end # Handle attributes diff --git a/lib/multi_xml/parsers/nokogiri.rb b/lib/multi_xml/parsers/nokogiri.rb index 295ec51..661fedb 100644 --- a/lib/multi_xml/parsers/nokogiri.rb +++ b/lib/multi_xml/parsers/nokogiri.rb @@ -33,14 +33,12 @@ def to_hash end module Node #:nodoc: - CONTENT_ROOT = '__content__'.freeze unless defined?(CONTENT_ROOT) - # Convert XML document to hash # # hash:: # Hash to merge the converted element into. def to_hash(hash={}) - node_hash = {CONTENT_ROOT => ''} + node_hash = {MultiXml::CONTENT_ROOT => ''} # Insert node hash into parent hash correctly. case hash[name] @@ -54,13 +52,13 @@ def to_hash(hash={}) if c.element? c.to_hash(node_hash) elsif c.text? || c.cdata? - node_hash[CONTENT_ROOT] << c.content + node_hash[MultiXml::CONTENT_ROOT] << c.content end end # Remove content node if it is empty - if node_hash[CONTENT_ROOT].strip.empty? - node_hash.delete(CONTENT_ROOT) + if node_hash[MultiXml::CONTENT_ROOT].strip.empty? + node_hash.delete(MultiXml::CONTENT_ROOT) end # Handle attributes diff --git a/lib/multi_xml/parsers/rexml.rb b/lib/multi_xml/parsers/rexml.rb index dc85b16..d55f7fe 100644 --- a/lib/multi_xml/parsers/rexml.rb +++ b/lib/multi_xml/parsers/rexml.rb @@ -6,8 +6,6 @@ module Rexml #:nodoc: extend self def parse_error; ::REXML::ParseException; end - CONTENT_ROOT = '__content__'.freeze unless defined?(CONTENT_ROOT) - # Parse an XML Document string or IO into a simple hash using REXML # # xml:: @@ -72,7 +70,7 @@ def merge_texts!(hash, element) # must use value to prevent double-escaping texts = '' element.texts.each { |t| texts << t.value } - merge!(hash, CONTENT_ROOT, texts) + merge!(hash, MultiXml::CONTENT_ROOT, texts) end end