Class that will build the hash while the XML document is being parsed using SAX events.
Methods
- current_hash
- on_cdata_block
- on_characters
- on_end_document
- on_end_element
- on_start_document
- on_start_element
Included Modules
- LibXML::XML::SaxParser::Callbacks
Constants
| CONTENT_KEY | = | '__content__'.freeze |
| HASH_SIZE_KEY | = | '__hash_size__'.freeze |
Attributes
| [R] | hash |
Public Instance methods
[ show source ]
# File activesupport/lib/active_support/xml_mini/libxmlsax.rb, line 19
19: def current_hash
20: @hash_stack.last
21: end
Alias for on_characters
This method is also aliased as
on_cdata_block
[ show source ]
# File activesupport/lib/active_support/xml_mini/libxmlsax.rb, line 53
53: def on_characters(string)
54: current_hash[CONTENT_KEY] << string
55: end
[ show source ]
# File activesupport/lib/active_support/xml_mini/libxmlsax.rb, line 28
28: def on_end_document
29: @hash = @hash_stack.pop
30: @hash.delete(CONTENT_KEY)
31: end
[ show source ]
# File activesupport/lib/active_support/xml_mini/libxmlsax.rb, line 46
46: def on_end_element(name)
47: if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ''
48: current_hash.delete(CONTENT_KEY)
49: end
50: @hash_stack.pop
51: end
[ show source ]
# File activesupport/lib/active_support/xml_mini/libxmlsax.rb, line 23
23: def on_start_document
24: @hash = { CONTENT_KEY => '' }
25: @hash_stack = [@hash]
26: end
[ show source ]
# File activesupport/lib/active_support/xml_mini/libxmlsax.rb, line 33
33: def on_start_element(name, attrs = {})
34: new_hash = { CONTENT_KEY => '' }.merge(attrs)
35: new_hash[HASH_SIZE_KEY] = new_hash.size + 1
36:
37: case current_hash[name]
38: when Array then current_hash[name] << new_hash
39: when Hash then current_hash[name] = [current_hash[name], new_hash]
40: when nil then current_hash[name] = new_hash
41: end
42:
43: @hash_stack.push(new_hash)
44: end