Module: Duxml::Saxer

Included in:
Duxml
Defined in:
lib/duxml/saxer.rb

Defined Under Namespace

Classes: DocuLiner

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ioObject

Returns the value of attribute io.



9
10
11
# File 'lib/duxml/saxer.rb', line 9

def io
  @io
end

Instance Method Details

#sax(path_or_xml, obs = nil) ⇒ Doc, Element Also known as: parse

Returns finished document with each Element’s line and column info added.

Parameters:

  • path_or_xml (String)

    path of file to parse or XML as String

Returns:

  • (Doc, Element)

    finished document with each Element’s line and column info added



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/duxml/saxer.rb', line 12

def sax(path_or_xml, obs=nil)
  doc_or_no = File.exists?(path_or_xml)
  io = doc_or_no ? File.open(path_or_xml): path_or_xml
  saxer = DocuLiner.new(Duxml::Doc.new, obs)
  Ox.sax_parse(saxer, io, {convert_special: true, symbolize: false})
  doc = saxer.cursor
  return doc.root unless doc_or_no
  doc.add_observer obs if obs and doc.count_observers < 1
  doc.path = path_or_xml
  doc
end