Class that will build the hash while the XML document is being parsed using SAX events.
Methods
Constants
CONTENT_KEY | = | '__content__'.freeze |
HASH_SIZE_KEY | = | '__hash_size__'.freeze |
Attributes
[R] | hash |
Public Instance methods
Alias for characters
This method is also aliased as
cdata_block
[ show source ]
# File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 55 55: def characters(string) 56: current_hash[CONTENT_KEY] << string 57: end
[ show source ]
# File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 17 17: def current_hash 18: @hash_stack.last 19: end
[ show source ]
# File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 26 26: def end_document 27: raise "Parse stack not empty!" if @hash_stack.size > 1 28: end
[ show source ]
# File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 48 48: def end_element(name) 49: if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == '' 50: current_hash.delete(CONTENT_KEY) 51: end 52: @hash_stack.pop 53: end
[ show source ]
# File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 30 30: def error(error_message) 31: raise error_message 32: end
[ show source ]
# File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 21 21: def start_document 22: @hash = {} 23: @hash_stack = [@hash] 24: end
[ show source ]
# File activesupport/lib/active_support/xml_mini/nokogirisax.rb, line 34 34: def start_element(name, attrs = []) 35: new_hash = { CONTENT_KEY => '' } 36: new_hash[attrs.shift] = attrs.shift while attrs.length > 0 37: new_hash[HASH_SIZE_KEY] = new_hash.size + 1 38: 39: case current_hash[name] 40: when Array then current_hash[name] << new_hash 41: when Hash then current_hash[name] = [current_hash[name], new_hash] 42: when nil then current_hash[name] = new_hash 43: end 44: 45: @hash_stack.push(new_hash) 46: end