Class: SOAP::Parser
Defined Under Namespace
Classes: FormatDecodeError, ParseError, ParseFrame, UnexpectedElementError
Constant Summary
Constants included from SOAP
AttrActor, AttrActorName, AttrArrayType, AttrArrayTypeName, AttrEncodingStyle, AttrEncodingStyleName, AttrHref, AttrHrefName, AttrId, AttrIdName, AttrMustUnderstand, AttrMustUnderstandName, AttrOffset, AttrOffsetName, AttrPosition, AttrPositionName, AttrRoot, AttrRootName, Base64Literal, Charset, EleBody, EleBodyName, EleEnvelope, EleEnvelopeName, EleFault, EleFaultActor, EleFaultActorName, EleFaultCode, EleFaultCodeName, EleFaultDetail, EleFaultDetailName, EleFaultName, EleFaultString, EleFaultStringName, EleHeader, EleHeaderName, EncodingNamespace, EnvelopeNamespace, LiteralNamespace, MediaType, NextActor, PropertyName, RPCRouter, RPCServerException, RPCUtils, SOAPGenerator, SOAPProxy, TypeMap, VERSION, ValueArray, ValueArrayName
Instance Attribute Summary collapse
-
#allow_unqualified_element ⇒ Object
Returns the value of attribute allow_unqualified_element.
-
#decode_typemap ⇒ Object
Returns the value of attribute decode_typemap.
-
#default_encodingstyle ⇒ Object
Returns the value of attribute default_encodingstyle.
-
#envelopenamespace ⇒ Object
Returns the value of attribute envelopenamespace.
Instance Method Summary collapse
- #characters(text) ⇒ Object
- #charset ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(opt = {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse(string_or_readable) ⇒ Object
- #start_element(name, raw_attrs) ⇒ Object
Constructor Details
#initialize(opt = {}) ⇒ Parser
Returns a new instance of Parser.
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/soap/parser.rb', line 77 def initialize(opt = {}) @opt = opt @parser = XSD::XMLParser.create_parser(self, opt) @parsestack = nil @recycleframe = nil @lastnode = nil @handlers = {} @envelopenamespace = opt[:envelopenamespace] || EnvelopeNamespace @default_encodingstyle = opt[:default_encodingstyle] || EncodingNamespace @decode_typemap = opt[:decode_typemap] || nil @allow_unqualified_element = opt[:allow_unqualified_element] || false end |
Instance Attribute Details
#allow_unqualified_element ⇒ Object
Returns the value of attribute allow_unqualified_element.
75 76 77 |
# File 'lib/soap/parser.rb', line 75 def allow_unqualified_element @allow_unqualified_element end |
#decode_typemap ⇒ Object
Returns the value of attribute decode_typemap.
74 75 76 |
# File 'lib/soap/parser.rb', line 74 def decode_typemap @decode_typemap end |
#default_encodingstyle ⇒ Object
Returns the value of attribute default_encodingstyle.
73 74 75 |
# File 'lib/soap/parser.rb', line 73 def default_encodingstyle @default_encodingstyle end |
#envelopenamespace ⇒ Object
Returns the value of attribute envelopenamespace.
72 73 74 |
# File 'lib/soap/parser.rb', line 72 def envelopenamespace @envelopenamespace end |
Instance Method Details
#characters(text) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/soap/parser.rb', line 152 def characters(text) # Ignore Text outside of SOAP Envelope. if lastframe = @parsestack.last # Need not to be cloned because character does not have attr. decode_text(lastframe.ns, text, lastframe.handler) end end |
#charset ⇒ Object
90 91 92 |
# File 'lib/soap/parser.rb', line 90 def charset @parser.charset end |
#end_element(name) ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'lib/soap/parser.rb', line 160 def end_element(name) lastframe = @parsestack.pop unless name == lastframe.name raise UnexpectedElementError.new("Closing element name '#{ name }' does not match with opening element '#{ lastframe.name }'.") end decode_tag_end(lastframe.ns, lastframe.node, lastframe.handler) @lastnode = lastframe.node.node @recycleframe = lastframe end |
#parse(string_or_readable) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/soap/parser.rb', line 94 def parse(string_or_readable) @parsestack = [] @lastnode = nil @handlers.each do |uri, handler| handler.decode_prologue end @parser.do_parse(string_or_readable) unless @parsestack.empty? raise FormatDecodeError.new("Unbalanced tag in XML.") end @handlers.each do |uri, handler| handler.decode_epilogue end @lastnode end |
#start_element(name, raw_attrs) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/soap/parser.rb', line 115 def start_element(name, raw_attrs) lastframe = @parsestack.last ns = parent = parent_encodingstyle = nil if lastframe ns = lastframe.ns parent = lastframe.node parent_encodingstyle = lastframe.encodingstyle else ns = SOAP::NS.new parent = ParseFrame::NodeContainer.new(nil) parent_encodingstyle = nil end # ns might be the same ns, raw_attrs = XSD::XMLParser.filter_ns(ns, raw_attrs) attrs = decode_attrs(ns, raw_attrs) encodingstyle = attrs[AttrEncodingStyleName] # Children's encodingstyle is derived from its parent. if encodingstyle.nil? if parent.node.is_a?(SOAPHeader) encodingstyle = LiteralNamespace else encodingstyle = parent_encodingstyle || @default_encodingstyle end end handler = find_handler(encodingstyle) unless handler raise FormatDecodeError.new("Unknown encodingStyle: #{ encodingstyle }.") end node = decode_tag(ns, name, attrs, parent, handler) if @recycleframe @parsestack << @recycleframe.update(ns, name, node, encodingstyle, handler) @recycleframe = nil else @parsestack << ParseFrame.new(ns, name, node, encodingstyle, handler) end end |