class Aws::Xml::Parser
A SAX-style XML parser that uses a shape context to handle types.
Constants
- FRAME_CLASSES
Public Class Methods
engine()
click to toggle source
@return [Class] Returns the default parsing engine.
One of: * {OxEngine} * {OgaEngine} * {LibxmlEngine} * {NokogiriEngine} * {RexmlEngine}
# File lib/aws-sdk-core/xml/parser.rb, line 72 def engine @engine end
engine=(engine)
click to toggle source
@param [Symbol,Class] engine
Must be one of the following values: * :ox * :oga * :libxml * :nokogiri * :rexml
# File lib/aws-sdk-core/xml/parser.rb, line 59 def engine= engine @engine = Class === engine ? engine : load_engine(engine) end
new(rules, options = {})
click to toggle source
@param [Seahorse::Model::ShapeRef] rules
# File lib/aws-sdk-core/xml/parser.rb, line 18 def initialize(rules, options = {}) @rules = rules @engine = options[:engine] || self.class.engine end
Private Class Methods
load_engine(name)
click to toggle source
# File lib/aws-sdk-core/xml/parser.rb, line 78 def load_engine(name) require "aws-sdk-core/xml/parser/engines/#{name}" const_name = name[0].upcase + name[1..-1] + 'Engine' const_get(const_name) end
try_load_engine(name)
click to toggle source
# File lib/aws-sdk-core/xml/parser.rb, line 84 def try_load_engine(name) load_engine(name) rescue LoadError false end
Public Instance Methods
parse(xml, target = nil, &unhandled_callback)
click to toggle source
Parses the XML document, returning a parsed structure.
If you pass a block, this will yield for XML elements that are not modeled in the rules given to the constructor.
parser.parse(xml) do |path, value| puts "uhandled: #{path.join('/')} - #{value}" end
The purpose of the unhandled callback block is to allow callers to access values such as the EC2 request ID that are part of the XML body but not part of the operation result.
@param [String] xml An XML document string to parse. @param [Structure] target (nil) @return [Structure]
# File lib/aws-sdk-core/xml/parser.rb, line 41 def parse(xml, target = nil, &unhandled_callback) xml = '<xml/>' if xml.nil? or xml.empty? stack = Stack.new(@rules, target, &unhandled_callback) @engine.new(stack).parse(xml.to_s) stack.result end