Class: XSD::XMLParser::XMLScanner
- Inherits:
-
Parser
show all
- Includes:
- XMLScan::Visitor
- Defined in:
- lib/xsd/xmlparser/xmlscanner.rb
Constant Summary
collapse
- 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
Instance Method Details
#do_parse(string_or_readable) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 21
def do_parse(string_or_readable)
@attrs = {}
@curattr = nil
@scanner = XMLScan::XMLScanner.new(self)
@scanner.kcode = XSD::Charset.charset_str(charset) if charset
@scanner.parse(string_or_readable)
end
|
#on_attr_charref(code) ⇒ Object
126
127
128
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 126
def on_attr_charref(code)
@curattr << [code].pack('U')
end
|
#on_attr_charref_hex(code) ⇒ Object
130
131
132
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 130
def on_attr_charref_hex(code)
on_attr_charref(code)
end
|
#on_attr_entityref(ref) ⇒ Object
122
123
124
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 122
def on_attr_entityref(ref)
@curattr << ENTITY_REF_MAP[ref]
end
|
#on_attr_value(str) ⇒ Object
118
119
120
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 118
def on_attr_value(str)
@curattr << str
end
|
#on_attribute(name) ⇒ Object
114
115
116
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 114
def on_attribute(name)
@attrs[name] = @curattr = ''
end
|
#on_cdata(str) ⇒ Object
86
87
88
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 86
def on_cdata(str)
characters(str)
end
|
#on_chardata(str) ⇒ Object
def on_pi(target, pi); end
82
83
84
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 82
def on_chardata(str)
characters(str)
end
|
#on_charref(code) ⇒ Object
98
99
100
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 98
def on_charref(code)
characters([code].pack('U'))
end
|
#on_charref_hex(code) ⇒ Object
102
103
104
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 102
def on_charref_hex(code)
on_charref(code)
end
|
#on_entityref(ref) ⇒ Object
94
95
96
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 94
def on_entityref(ref)
characters(ENTITY_REF_MAP[ref])
end
|
#on_etag(name) ⇒ Object
90
91
92
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 90
def on_etag(name)
end_element(name)
end
|
#on_stag(name) ⇒ Object
110
111
112
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 110
def on_stag(name)
@attrs = {}
end
|
#on_stag_end(name) ⇒ Object
141
142
143
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 141
def on_stag_end(name)
start_element(name, @attrs)
end
|
#on_stag_end_empty(name) ⇒ Object
def on_attribute_end(name); end
136
137
138
139
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 136
def on_stag_end_empty(name)
on_stag_end(name)
on_etag(name)
end
|
#on_xmldecl_encoding(str) ⇒ Object
64
65
66
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 64
def on_xmldecl_encoding(str)
self.scanner_kcode = str
end
|
#on_xmldecl_version(str) ⇒ Object
60
61
62
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 60
def on_xmldecl_version(str)
end
|
#parse_error(msg) ⇒ Object
42
43
44
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 42
def parse_error(msg)
raise ParseError.new(msg)
end
|
#scanner_kcode=(charset) ⇒ Object
29
30
31
32
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 29
def scanner_kcode=(charset)
@scanner.kcode = XSD::Charset.charset_str(charset) if charset
self.xmldecl_encoding = charset
end
|
#valid_error(msg) ⇒ Object
50
51
52
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 50
def valid_error(msg)
raise NotValidError.new(msg)
end
|
#warning(msg) ⇒ Object
54
55
56
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 54
def warning(msg)
warn(msg)
end
|
46
47
48
|
# File 'lib/xsd/xmlparser/xmlscanner.rb', line 46
def wellformed_error(msg)
raise NotWellFormedError.new(msg)
end
|