Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在Feedjira解析器类中访问xml_Ruby On Rails_Ruby_Xml_Feedjira - Fatal编程技术网

Ruby on rails 如何在Feedjira解析器类中访问xml

Ruby on rails 如何在Feedjira解析器类中访问xml,ruby-on-rails,ruby,xml,feedjira,Ruby On Rails,Ruby,Xml,Feedjira,假设我有以下Feedjira嵌套解析器子类。如何访问主干、分支和叶类的xml,以便在发生错误时记录/保存它?最好只是解析元素的xml,但对于分支或叶,我会使用整个主干的xml 谢谢 module Feedjira module Parser class Trunk include SAXMachine include FeedEntryUtilities element :trunkName elements :branch, as:

假设我有以下Feedjira嵌套解析器子类。如何访问主干、分支和叶类的xml,以便在发生错误时记录/保存它?最好只是解析元素的xml,但对于分支或叶,我会使用整个主干的xml

谢谢

module Feedjira
  module Parser
    class Trunk
      include SAXMachine
      include FeedEntryUtilities

      element :trunkName
      elements :branch, as: :branches, class: Branch

      def createModel
        begin
          trunk = ActiveRecordTrunk.create( name: trunkName )
          branches.each_index do |n|
            branch = branches[ n ].createModel
            branch.trunk_id = trunk.id
            branch.save!
          end
        rescue StandardError => e
          # log the error and the xml for this trunk element.  HOW??
          ::Rails.logger.error "Parse Error, xml = #{ xml }"
        end
      end
    end

    class Branch
      include SAXMachine
      include FeedEntryUtilities

      element :branchName
      elements :leaf, as: :leaves, class: Leaf

      def createModel
        begin
          trunk = ActiveRecordBranch.create( name: branchName )
          leaves.each_index do |n|
            leaf = leaves[ n ].createModel
            leaf.branch_id = branch.id
            leaf.save!
          end
        rescue StandardError => e
          # log the error and the xml for this branch element.  HOW??
          ::Rails.logger.error "Parse Error, xml = #{ xml }"
        end
      end
    end

    class Leaf
      include SAXMachine
      include FeedEntryUtilities

      element :leafName

      def createModel
        begin
          leaf = ActiveRecordLeaf.create( name: leafName )
        rescue StandardError => e
          # log the error and the xml for this leaf element.  HOW??
          ::Rails.logger.error "Parse Error, xml = #{ xml }"
        end
      end
    end
  end
end