|
Revision 1824, 1.1 kB
(checked in by nahi, 2 years ago)
|
- Copyright notice updated. add '2000-2007' uniformly.
|
- Property svn:eol-style set to
native
- Property svn:keywords set to
author date id revision
|
| Line | |
|---|
| 1 |
# XSD4R - XMLParser XML parser library. |
|---|
| 2 |
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. |
|---|
| 3 |
|
|---|
| 4 |
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can |
|---|
| 5 |
# redistribute it and/or modify it under the same terms of Ruby's license; |
|---|
| 6 |
# either the dual license version in 2003, or any later version. |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
require 'xsd/xmlparser' |
|---|
| 10 |
require 'xml/parser' |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
module XSD |
|---|
| 14 |
module XMLParser |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
class XMLParser < XSD::XMLParser::Parser |
|---|
| 18 |
class Listener < XML::Parser |
|---|
| 19 |
begin |
|---|
| 20 |
require 'xml/encoding-ja' |
|---|
| 21 |
include XML::Encoding_ja |
|---|
| 22 |
rescue LoadError |
|---|
| 23 |
# uconv may not be installed. |
|---|
| 24 |
end |
|---|
| 25 |
end |
|---|
| 26 |
|
|---|
| 27 |
def do_parse(string_or_readable) |
|---|
| 28 |
# XMLParser passes a String in utf-8. |
|---|
| 29 |
@charset = 'utf-8' |
|---|
| 30 |
@parser = Listener.new |
|---|
| 31 |
@parser.parse(string_or_readable) do |type, name, data| |
|---|
| 32 |
case type |
|---|
| 33 |
when XML::Parser::START_ELEM |
|---|
| 34 |
start_element(name, data) |
|---|
| 35 |
when XML::Parser::END_ELEM |
|---|
| 36 |
end_element(name) |
|---|
| 37 |
when XML::Parser::CDATA |
|---|
| 38 |
characters(data) |
|---|
| 39 |
else |
|---|
| 40 |
raise FormatDecodeError.new("Unexpected XML: #{ type }/#{ name }/#{ data }.") |
|---|
| 41 |
end |
|---|
| 42 |
end |
|---|
| 43 |
end |
|---|
| 44 |
|
|---|
| 45 |
add_factory(self) |
|---|
| 46 |
end |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
end |
|---|
| 50 |
end |
|---|