Class: XSD::XMLParser::LibXMLParser

Inherits:
Parser show all
Includes:
XML::SaxParser::Callbacks
Defined in:
lib/xsd/xmlparser/libxmlparser.rb

Constant Summary

ENTITY_REF_MAP =
{
  'lt' => '<',
  'gt' => '>',
  'amp' => '&',
  'quot' => '"',
  'apos' => '\''
}

Instance Attribute Summary

Attributes inherited from Parser

#charset

Instance Method Summary (collapse)

Methods inherited from Parser

add_factory, create_parser, factory, #initialize, #parse

Constructor Details

This class inherits a constructor from XSD::XMLParser::Parser

Instance Method Details

- (Object) do_parse(string_or_readable)



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xsd/xmlparser/libxmlparser.rb', line 20

def do_parse(string_or_readable)
  if string_or_readable.respond_to?(:read)
    string = string_or_readable.read
  else
    string = string_or_readable
  end
  # XMLParser passes a String in utf-8.
  @charset = 'utf-8'
  @parser = XML::SaxParser.string(string)
  @parser.callbacks = self
  @parser.parse
end

- (Object) on_cdata_block(cdata)



106
107
108
# File 'lib/xsd/xmlparser/libxmlparser.rb', line 106

def on_cdata_block(cdata)
  characters(cdata)
end

- (Object) on_characters(chars)



82
83
84
# File 'lib/xsd/xmlparser/libxmlparser.rb', line 82

def on_characters(chars)
  characters(chars)
end

- (Object) on_end_element(name)



74
75
76
# File 'lib/xsd/xmlparser/libxmlparser.rb', line 74

def on_end_element(name)
  end_element(name)
end

- (Object) on_external_subset(name, external_id, system_id)



110
111
112
# File 'lib/xsd/xmlparser/libxmlparser.rb', line 110

def on_external_subset(name, external_id, system_id)
  nil
end

- (Object) on_parser_error(msg)

Raises:



98
99
100
# File 'lib/xsd/xmlparser/libxmlparser.rb', line 98

def on_parser_error(msg)
  raise ParseError.new(msg)
end

- (Object) on_parser_fatal_error(msg)

Raises:



102
103
104
# File 'lib/xsd/xmlparser/libxmlparser.rb', line 102

def on_parser_fatal_error(msg)
  raise ParseError.new(msg)
end

- (Object) on_parser_warning(msg)

def on_comment(msg)

nil

end



94
95
96
# File 'lib/xsd/xmlparser/libxmlparser.rb', line 94

def on_parser_warning(msg)
  warn(msg)
end

- (Object) on_reference(name)



78
79
80
# File 'lib/xsd/xmlparser/libxmlparser.rb', line 78

def on_reference(name)
  characters(ENTITY_REF_MAP[name])
end

- (Object) on_start_element_ns(name, attributes, prefix, uri, namespaces)

def on_end_document()

nil

end



65
66
67
68
69
70
71
72
# File 'lib/xsd/xmlparser/libxmlparser.rb', line 65

def on_start_element_ns(name, attributes, prefix, uri, namespaces)
  name = "#{prefix}:#{name}" unless prefix.nil?
  namespaces.each do |key,value|
    nsprefix = key.nil? ? "xmlns" : "xmlns:#{key}"
    attributes[nsprefix] = value
  end
  start_element(name, attributes)
end