Class: XSD::XMLParser::Nokogiri

Inherits:
Parser
  • Object
show all
Defined in:
lib/xsd/xmlparser/nokogiri.rb

Overview

Nokogiri XML parser for soap4r.

Nokogiri may be used as the XML parser in soap4r. Simply require ‘xsd/xmlparser/nokogiri’ in your soap4r applications, and soap4r will use Nokogiri as it’s XML parser. No other changes should be required to use Nokogiri as the XML parser.

Example (using UW ITS Web Services):

require 'rubygems'
require 'nokogiri'
gem 'soap4r'
require 'defaultDriver'
require 'xsd/xmlparser/nokogiri'

obj = AvlPortType.new
obj.getLatestByRoute(obj.getAgencies.first, 8).each do |bus|
  p "#{bus.routeID}, #{bus.longitude}, #{bus.latitude}"
end

Instance Method Summary collapse

Constructor Details

#initialize(host, opt = {}) ⇒ Nokogiri

Create a new XSD parser with host and opt



29
30
31
32
# File 'lib/xsd/xmlparser/nokogiri.rb', line 29

def initialize host, opt = {}
  super
  @parser = ::Nokogiri::XML::SAX::Parser.new(self, @charset || 'UTF-8')
end

Instance Method Details

#cdata_block(string) ⇒ Object

Handle cdata_blocks containing string



61
62
63
# File 'lib/xsd/xmlparser/nokogiri.rb', line 61

def cdata_block string
  characters string
end

#do_parse(string_or_readable) ⇒ Object

Start parsing string_or_readable



36
37
38
# File 'lib/xsd/xmlparser/nokogiri.rb', line 36

def do_parse string_or_readable
  @parser.parse(string_or_readable)
end

#end_element(name) ⇒ Object

Handle the end_element event with name



48
49
50
# File 'lib/xsd/xmlparser/nokogiri.rb', line 48

def end_element name
  super
end

#error(msg) ⇒ Object Also known as: warning

Handle errors with message msg

Raises:

  • (ParseError)


54
55
56
# File 'lib/xsd/xmlparser/nokogiri.rb', line 54

def error msg
  raise ParseError.new(msg)
end

#start_element(name, attrs = []) ⇒ Object

Handle the start_element event with name and attrs



42
43
44
# File 'lib/xsd/xmlparser/nokogiri.rb', line 42

def start_element name, attrs = []
  super(name, Hash[*attrs.flatten])
end