Module: Rfm::XmlParser

Extended by:
Config, XmlParser
Included in:
XmlParser
Defined in:
lib/rfm/utilities/xml_parser.rb

Constant Summary collapse

BACKENDS =

Backend definitions & configurations

ActiveSupport::OrderedHash.new

Instance Method Summary collapse

Methods included from Config

config, config_clear, get_config, sanitize_config

Instance Method Details

#backend(name = nil) ⇒ Object

Shortcut to XmlMini config getter. If a parameter is passed, it will be used to get the local backend description from the BACKENDS hash, instead of the XmlMini backend.



74
75
76
77
# File 'lib/rfm/utilities/xml_parser.rb', line 74

def backend(name=nil)
	return ActiveSupport::XmlMini.backend unless name
	get_backend_from_hash(name)
end

#backend=(name) ⇒ Object

Shortcut to XmlMini config setter.



80
81
82
83
84
85
86
# File 'lib/rfm/utilities/xml_parser.rb', line 80

def backend=(name)
	if name.is_a? Symbol
		set_backend_via_hash(name)
	else
		ActiveSupport::XmlMini.backend = name
	end
end

#new(string_or_file, opts = {}) ⇒ Object

Main parsing method. Options :namespace => false # strip out namespace (default) :parser => :libxml, :libxmlsax, :nokogirisax, :nokogiri, :hpricot, :rexml :parser => CustomParsingModule # see ActiveSupport::XmlMini



48
49
50
51
52
53
54
55
56
57
# File 'lib/rfm/utilities/xml_parser.rb', line 48

def new(string_or_file, opts={})
	string_or_file.gsub!(/xmlns=\"[^\"]*\"/,'') if (string_or_file.class == String and opts[:namespace] == false)
	unless opts[:parser] and get_backend_from_hash(opts[:parser]).to_s != self.backend.to_s
		warn "XmlParser default: #{ActiveSupport::XmlMini.backend.to_s}" if get_config[:log_parser] == true
		ActiveSupport::XmlMini.parse(string_or_file)
	else
		warn "XmlParser backend: #{get_backend_from_hash(opts[:parser]).to_s}" if get_config[:log_parser] == true
		ActiveSupport::XmlMini.with_backend(get_backend_from_hash(opts[:parser])) {ActiveSupport::XmlMini.parse(string_or_file)}
	end
end

#parse(string_or_file, opts = {}) ⇒ Object

Creates new hash with #new, plus extends the hash with result-dependent translation class.



60
61
62
63
64
65
66
67
68
69
# File 'lib/rfm/utilities/xml_parser.rb', line 60

def parse(string_or_file, opts={})
	doc = new(string_or_file, opts)
	case true
		when doc.has_key?('fmresultset') ; doc.extend(Fmresultset)
		when doc.has_key?('FMPXMLRESULT') ; doc.extend(Fmpxmlresult)
		when doc.has_key?('FMPDSORESULT') ; doc.extend(Fmpdsoresult)
		when doc.has_key?('FMPXMLLAYOUT') ; doc.extend(Fmpxmllayout)
		else doc
	end
end