Class: AXML::XMLParser::Parser
- Inherits:
-
AXML::XMLParser
- Object
- AXML::XMLParser
- AXML::XMLParser::Parser
- Defined in:
- lib/axml/xmlparser.rb
Constant Summary collapse
- NotBlankText_re =
/[^\s+]+/m
Constants included from AXML
CLASS_MAPPINGS, DEFAULTS, PREFERRED, WARN
Instance Attribute Summary collapse
-
#root ⇒ Object
returns the first node found in the document.
Instance Method Summary collapse
- #character(data) ⇒ Object
- #endElement(name) ⇒ Object
-
#initialize ⇒ Parser
constructor
takes opts from AXML::parse method.
- #set_no_keep_blanks ⇒ Object
-
#set_single_text_indices(el_name) ⇒ Object
returns text as an array for each occurence of the specified element: [start_index, num_bytes].
- #startElement(name, attributes) ⇒ Object
Methods inherited from AXML::XMLParser
Methods included from AXML
Constructor Details
Instance Attribute Details
#root ⇒ Object
returns the first node found in the document
44 45 46 |
# File 'lib/axml/xmlparser.rb', line 44 def root @root.child end |
Instance Method Details
#character(data) ⇒ Object
105 106 107 |
# File 'lib/axml/xmlparser.rb', line 105 def character(data) @cur.text << data end |
#endElement(name) ⇒ Object
109 110 111 |
# File 'lib/axml/xmlparser.rb', line 109 def endElement(name) @cur = @cur.parent end |
#set_no_keep_blanks ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/axml/xmlparser.rb', line 48 def set_no_keep_blanks instance_eval do def endElement(name) unless NotBlankText_re.match(@cur.text) @cur.text = nil end @cur = @cur.parent end end end |
#set_single_text_indices(el_name) ⇒ Object
returns text as an array for each occurence of the specified element: [start_index, num_bytes]
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/axml/xmlparser.rb', line 60 def set_single_text_indices(el_name) @el_name = el_name instance_eval do def startElement(name, attributes) text = if name == @el_name ; [] else ; '' end new_el = ::AXML::El.new(@cur, name, attributes, text, []) @cur.add_node(new_el) @cur = new_el end def character(data) if @cur.text.is_a? Array @cur.text << byteIndex else @cur.text << data end end tmpvar = $VERBOSE ; $VERBOSE = nil def endElement(name) if @cur.text.is_a? Array @cur.text << (byteIndex - @cur.text.first) end @cur = @cur.parent end $VERBOSE = tmpvar end end |