class Krikri::XmlParser
An XmlParser
@see Krikri::Parser
Public Class Methods
new(record, root_path = '/', ns = {})
click to toggle source
@param record [Krikri::OriginalRecord] a record whose properties can be parsed by the parser instance. @param root_path [String] XPath that identifies the root path for the desired parse root. @param ns [Hash] A hash containing namespaces to identify up front. For each hash item, the key refers to the prefix used, and its value is the associated namespace URI.
Calls superclass method
Krikri::Parser::new
# File lib/krikri/parsers/xml_parser.rb, line 14 def initialize(record, root_path = '/', ns = {}) xml = Nokogiri::XML(record.to_s) ns = namespaces_from_xml(xml).merge(ns) root_node = xml.at_xpath(root_path, ns) raise EmptyRootNodeError if root_node.nil? @root = Value.new(root_node, ns) super(record) end
Private Instance Methods
namespaces_from_xml(xml)
click to toggle source
# File lib/krikri/parsers/xml_parser.rb, line 25 def namespaces_from_xml(xml) namespaces = xml.collect_namespaces.map do |k, v| [k.gsub('xmlns:', ''), v] end namespaces.to_h end