Class: Krikri::XmlParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/krikri/parsers/xml_parser.rb

Overview

An XmlParser

See Also:

Defined Under Namespace

Classes: EmptyRootNodeError, Value

Instance Attribute Summary

Attributes inherited from Parser

#record, #root

Instance Method Summary collapse

Methods inherited from Parser

#local_name, parse

Constructor Details

#initialize(record, root_path = '/', ns = {}) ⇒ XmlParser

be parsed by the parser instance. the desired parse root. For each hash item, the key refers to the prefix used, and its value is the associated namespace URI.

Parameters:

  • record (Krikri::OriginalRecord)

    a record whose properties can

  • root_path (String) (defaults to: '/')

    XPath that identifies the root path for

  • ns (Hash) (defaults to: {})

    A hash containing namespaces to identify up front.

Raises:



14
15
16
17
18
19
20
21
# 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