Class: Aws::Xml::Parser Private

Inherits:
Object
  • Object
show all
Includes:
Seahorse::Model::Shapes
Defined in:
lib/aws-sdk-core/xml/parser.rb,
lib/aws-sdk-core/xml/parser/frame.rb,
lib/aws-sdk-core/xml/parser/stack.rb,
lib/aws-sdk-core/xml/parser/ox_engine.rb,
lib/aws-sdk-core/xml/parser/oga_engine.rb,
lib/aws-sdk-core/xml/parser/rexml_engine.rb,
lib/aws-sdk-core/xml/parser/libxml_engine.rb,
lib/aws-sdk-core/xml/parser/parsing_error.rb,
lib/aws-sdk-core/xml/parser/nokogiri_engine.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A SAX-style XML parser that uses a shape context to handle types.

Defined Under Namespace

Classes: BlobFrame, BooleanFrame, FlatListFrame, FloatFrame, Frame, IntegerFrame, LibxmlEngine, ListFrame, MapEntryFrame, MapFrame, NokogiriEngine, NullFrame, OgaEngine, OxEngine, ParsingError, RexmlEngine, Stack, StringFrame, StructureFrame, TimestampFrame, UnknownMemberFrame

Constant Summary collapse

FRAME_CLASSES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  NilClass => NullFrame,
  BlobShape => BlobFrame,
  BooleanShape => BooleanFrame,
  FloatShape => FloatFrame,
  IntegerShape => IntegerFrame,
  ListShape => ListFrame,
  MapShape => MapFrame,
  StringShape => StringFrame,
  StructureShape => StructureFrame,
  UnionShape => StructureFrame,
  TimestampShape => TimestampFrame,
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules, options = {}) ⇒ Parser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Parser.

Parameters:

  • rules (Seahorse::Model::ShapeRef)


9
10
11
12
# File 'lib/aws-sdk-core/xml/parser.rb', line 9

def initialize(rules, options = {})
  @rules = rules
  @engine = options[:engine] || self.class.engine
end

Class Method Details

.engineClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the default parsing engine. One of:

Returns:



61
62
63
64
# File 'lib/aws-sdk-core/xml/parser.rb', line 61

def engine
  set_default_engine unless @engine
  @engine
end

.engine=(engine) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • engine (Symbol, Class)

    Must be one of the following values:

    • :ox

    • :oga

    • :libxml

    • :nokogiri

    • :rexml



49
50
51
# File 'lib/aws-sdk-core/xml/parser.rb', line 49

def engine=(engine)
  @engine = Class === engine ? engine : load_engine(engine)
end

.set_default_engineObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
69
70
71
72
73
74
75
# File 'lib/aws-sdk-core/xml/parser.rb', line 66

def set_default_engine
  [:ox, :oga, :libxml, :nokogiri, :rexml].each do |name|
    @engine ||= try_load_engine(name)
  end
  unless @engine
    raise 'Unable to find a compatible xml library. ' \
    'Ensure that you have installed or added to your Gemfile one of ' \
    'ox, oga, libxml, nokogiri or rexml'
  end
end

Instance Method Details

#parse(xml, target = nil, &unhandled_callback) ⇒ Structure

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Parameters:

  • xml (String)

    An XML document string to parse.

  • target (Structure) (defaults to: nil)

    (nil)

Returns:



32
33
34
35
36
37
# File 'lib/aws-sdk-core/xml/parser.rb', line 32

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