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