module Exlibris::Primo::XmlUtil
Utility for parsing and building XML
Attributes
raw_xml[R]
Public Class Methods
included(klass)
click to toggle source
# File lib/exlibris/primo/xml_util.rb, line 9 def self.included(klass) klass.class_eval do extend ClassAttributes end end
Public Instance Methods
to_hash()
click to toggle source
# File lib/exlibris/primo/xml_util.rb, line 62 def to_hash Hash.from_xml(to_xml) end
to_json()
click to toggle source
# File lib/exlibris/primo/xml_util.rb, line 70 def to_json to_hash.to_json end
to_xml()
click to toggle source
# File lib/exlibris/primo/xml_util.rb, line 66 def to_xml xml.to_xml(xml_options).strip end
Protected Instance Methods
build_xml(options={})
click to toggle source
Returns an XML string and takes any args that are understood by Nokogiri::XML::Builder.
# File lib/exlibris/primo/xml_util.rb, line 30 def build_xml options={}, &block Nokogiri::XML::Builder.new(options.merge(:encoding => 'UTF-8'), &block).to_xml(xml_options).strip end
remove_namespaces_from_raw_xml(raw_xml, namespaces)
click to toggle source
# File lib/exlibris/primo/xml_util.rb, line 50 def remove_namespaces_from_raw_xml(raw_xml, namespaces) tmp_xml_with_namespaces = build_xml do |xml| xml.root(namespaces) do xml << raw_xml end end tmp_xml = Nokogiri::XML(tmp_xml_with_namespaces) tmp_xml.remove_namespaces! tmp_xml.root.children.first.to_xml(xml_options) end
xml()
click to toggle source
# File lib/exlibris/primo/xml_util.rb, line 40 def xml @xml ||= Nokogiri::XML(raw_xml, nil, 'UTF-8') end
xml_options()
click to toggle source
# File lib/exlibris/primo/xml_util.rb, line 35 def xml_options @xml_options ||= self.class.xml_options end
xml_without_namespaces()
click to toggle source
# File lib/exlibris/primo/xml_util.rb, line 45 def xml_without_namespaces xml.clone.remove_namespaces! end