Class: AXML::XMLParser

Inherits:
XMLParser
  • Object
show all
Defined in:
lib/axml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeXMLParser

takes opts from AXML::parse method



313
314
315
316
317
# File 'lib/axml.rb', line 313

def initialize
  #@keep_blanks = opts[:keep_blanks]
  @root = AXML::El.new(nil, "root", {}, '', [])
  @cur = @root
end

Instance Attribute Details

#rootObject

returns the first node found in the document



266
267
268
# File 'lib/axml.rb', line 266

def root
  @root.child
end

Instance Method Details

#character(data) ⇒ Object



325
326
327
# File 'lib/axml.rb', line 325

def character(data)
  @cur.text << data
end

#endElement(name) ⇒ Object



329
330
331
# File 'lib/axml.rb', line 329

def endElement(name)
  @cur = @cur.parent
end

#set_no_keep_blanksObject



270
271
272
273
274
275
276
277
278
279
# File 'lib/axml.rb', line 270

def set_no_keep_blanks
  instance_eval do
    def endElement(name)
      unless AXML::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]



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/axml.rb', line 282

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

    def endElement(name)
      if @cur.text.is_a? Array
        @cur.text << (byteIndex - @cur.text.first)
      end
      @cur = @cur.parent
    end
  end
end

#startElement(name, attributes) ⇒ Object



319
320
321
322
323
# File 'lib/axml.rb', line 319

def startElement(name, attributes)
  new_el = AXML::El.new(@cur, name, attributes, '', [])
  @cur.add_node(new_el)
  @cur = new_el
end