Sha256: cec97942faf1e45e25c977ea0c1be3dcfa1c23157cc9419160d4930ed3a63d2c

Contents?: true

Size: 1.17 KB

Versions: 12

Compression:

Stored size: 1.17 KB

Contents

require 'ndr_support/safe_file'
require 'ndr_import/helpers/file/xml'
require 'ndr_import/helpers/file/xml_streaming'
require_relative 'registry'

module NdrImport
  # This is one of a collection of file handlers that deal with individual formats of data.
  # They can be instantiated directly or via the factory method Registry.tables
  module File
    # This class is a xml file handler that returns a single table.
    class Xml < Base
      include NdrImport::Helpers::File::Xml
      include NdrImport::Helpers::File::XmlStreaming

      private

      # Iterate through the file, yielding each 'xml_record_xpath' element in turn.
      def rows(&block)
        return enum_for(:rows) unless block

        xpath = @options['xml_record_xpath']

        if @options['slurp']
          doc = read_xml_file(@filename)
          doc.xpath(xpath).each(&block)
        else
          each_node(@filename, xpath, &block)
        end
      rescue StandardError => e
        raise("#{SafeFile.basename(@filename)} [#{e.class}: #{e.message}]")
      end
    end
    # Not all xml files may want to be registered, so 'xml' is not registered by design.
    Registry.register(Xml, 'xml_table')
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ndr_import-10.3.0 lib/ndr_import/file/xml.rb
ndr_import-10.2.0 lib/ndr_import/file/xml.rb
ndr_import-10.1.3 lib/ndr_import/file/xml.rb
ndr_import-10.1.2 lib/ndr_import/file/xml.rb
ndr_import-10.1.1 lib/ndr_import/file/xml.rb
ndr_import-10.1 lib/ndr_import/file/xml.rb
ndr_import-10.0 lib/ndr_import/file/xml.rb
ndr_import-9.1.0 lib/ndr_import/file/xml.rb
ndr_import-9.0.3 lib/ndr_import/file/xml.rb
ndr_import-9.0.2 lib/ndr_import/file/xml.rb
ndr_import-9.0.1 lib/ndr_import/file/xml.rb
ndr_import-9.0.0 lib/ndr_import/file/xml.rb