Sha256: 30eb8e2af3005b5ad1d1ca0d96e1181038ce94210d6a09fbb4b64378892b661d

Contents?: true

Size: 1.24 KB

Versions: 54

Compression:

Stored size: 1.24 KB

Contents

require "rexml/parsers/baseparser"
require "rexml/text"
require "rexml/document"

class Nori
  module Parser

    # = Nori::Parser::REXML
    #
    # REXML pull parser.
    module REXML

      def self.parse(xml, options)
        stack = []
        parser = ::REXML::Parsers::BaseParser.new(xml)

        while true
          event = unnormalize(parser.pull)
          case event[0]
          when :end_document
            break
          when :end_doctype, :start_doctype
            # do nothing
          when :start_element
            stack.push Nori::XMLUtilityNode.new(options, event[1], event[2])
          when :end_element
            if stack.size > 1
              temp = stack.pop
              stack.last.add_node(temp)
            end
          when :text, :cdata
            stack.last.add_node(event[1]) unless event[1].strip.length == 0 || stack.empty?
          end
        end
        stack.length > 0 ? stack.pop.to_hash : {}
      end

      def self.unnormalize(event)
        event.map! do |el|
          if el.is_a?(String)
            ::REXML::Text.unnormalize(el)
          elsif el.is_a?(Hash)
            el.each {|k,v| el[k] = ::REXML::Text.unnormalize(v)}
          else
            el
          end
        end
      end
    end
  end
end

Version data entries

54 entries across 46 versions & 7 rubygems

Version Path
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-1.9.7.1 vendor/bundle/ruby/2.4.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/gems/nori-2.6.0/lib/nori/parser/rexml.rb