soybean 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/bin/soybean +22 -0
- data/bin/xsd2ruby +90 -0
- data/lib/soybean.rb +11 -0
- data/lib/soybean/actions/generate_classes.rb +33 -0
- data/soybean.gemspec +236 -0
- data/spec/soybean_spec.rb +5 -0
- data/spec/spec_helper.rb +12 -0
- data/vendor/soap4r/soap/attachment.rb +109 -0
- data/vendor/soap4r/soap/attrproxy.rb +35 -0
- data/vendor/soap4r/soap/base_data.rb +1095 -0
- data/vendor/soap4r/soap/element.rb +278 -0
- data/vendor/soap4r/soap/encodingstyle/asp_dot_net_handler.rb +208 -0
- data/vendor/soap4r/soap/encodingstyle/handler.rb +121 -0
- data/vendor/soap4r/soap/encodingstyle/literal_handler.rb +196 -0
- data/vendor/soap4r/soap/encodingstyle/soap_handler.rb +560 -0
- data/vendor/soap4r/soap/filter.rb +14 -0
- data/vendor/soap4r/soap/filter/filterchain.rb +52 -0
- data/vendor/soap4r/soap/filter/handler.rb +32 -0
- data/vendor/soap4r/soap/filter/streamhandler.rb +30 -0
- data/vendor/soap4r/soap/generator.rb +299 -0
- data/vendor/soap4r/soap/header/handler.rb +62 -0
- data/vendor/soap4r/soap/header/handlerset.rb +71 -0
- data/vendor/soap4r/soap/header/mappinghandler.rb +48 -0
- data/vendor/soap4r/soap/header/simplehandler.rb +45 -0
- data/vendor/soap4r/soap/httpconfigloader.rb +140 -0
- data/vendor/soap4r/soap/mapping.rb +13 -0
- data/vendor/soap4r/soap/mapping/encodedregistry.rb +539 -0
- data/vendor/soap4r/soap/mapping/factory.rb +389 -0
- data/vendor/soap4r/soap/mapping/literalregistry.rb +392 -0
- data/vendor/soap4r/soap/mapping/mapping.rb +577 -0
- data/vendor/soap4r/soap/mapping/registry.rb +296 -0
- data/vendor/soap4r/soap/mapping/rubytype_factory.rb +446 -0
- data/vendor/soap4r/soap/mapping/schemadefinition.rb +171 -0
- data/vendor/soap4r/soap/mapping/type_map.rb +107 -0
- data/vendor/soap4r/soap/mapping/wsdlencodedregistry.rb +212 -0
- data/vendor/soap4r/soap/mapping/wsdlliteralregistry.rb +249 -0
- data/vendor/soap4r/soap/marshal.rb +60 -0
- data/vendor/soap4r/soap/mimemessage.rb +243 -0
- data/vendor/soap4r/soap/nestedexception.rb +43 -0
- data/vendor/soap4r/soap/net_http_client.rb +242 -0
- data/vendor/soap4r/soap/ns.rb +39 -0
- data/vendor/soap4r/soap/parser.rb +253 -0
- data/vendor/soap4r/soap/processor.rb +67 -0
- data/vendor/soap4r/soap/property.rb +340 -0
- data/vendor/soap4r/soap/proxy.rb +15 -0
- data/vendor/soap4r/soap/rpc/cgistub.rb +248 -0
- data/vendor/soap4r/soap/rpc/driver.rb +222 -0
- data/vendor/soap4r/soap/rpc/element.rb +375 -0
- data/vendor/soap4r/soap/rpc/httpserver.rb +143 -0
- data/vendor/soap4r/soap/rpc/method_def.rb +69 -0
- data/vendor/soap4r/soap/rpc/proxy.rb +573 -0
- data/vendor/soap4r/soap/rpc/router.rb +663 -0
- data/vendor/soap4r/soap/rpc/rpc.rb +26 -0
- data/vendor/soap4r/soap/rpc/soaplet.rb +201 -0
- data/vendor/soap4r/soap/rpc/standalone_server.rb +44 -0
- data/vendor/soap4r/soap/soap.rb +154 -0
- data/vendor/soap4r/soap/stream_handler.rb +302 -0
- data/vendor/soap4r/soap/version.rb +9 -0
- data/vendor/soap4r/soap/wsdl_driver.rb +165 -0
- data/vendor/soap4r/wsdl/binding.rb +66 -0
- data/vendor/soap4r/wsdl/data.rb +65 -0
- data/vendor/soap4r/wsdl/definitions.rb +237 -0
- data/vendor/soap4r/wsdl/documentation.rb +33 -0
- data/vendor/soap4r/wsdl/import.rb +81 -0
- data/vendor/soap4r/wsdl/importer.rb +39 -0
- data/vendor/soap4r/wsdl/info.rb +51 -0
- data/vendor/soap4r/wsdl/message.rb +55 -0
- data/vendor/soap4r/wsdl/operation.rb +152 -0
- data/vendor/soap4r/wsdl/operation_binding.rb +241 -0
- data/vendor/soap4r/wsdl/param.rb +94 -0
- data/vendor/soap4r/wsdl/parser.rb +165 -0
- data/vendor/soap4r/wsdl/part.rb +53 -0
- data/vendor/soap4r/wsdl/port.rb +67 -0
- data/vendor/soap4r/wsdl/port_type.rb +76 -0
- data/vendor/soap4r/wsdl/service.rb +62 -0
- data/vendor/soap4r/wsdl/soap/address.rb +41 -0
- data/vendor/soap4r/wsdl/soap/binding.rb +50 -0
- data/vendor/soap4r/wsdl/soap/body.rb +59 -0
- data/vendor/soap4r/wsdl/soap/cgi_stub_creator.rb +93 -0
- data/vendor/soap4r/wsdl/soap/class_def_creator.rb +437 -0
- data/vendor/soap4r/wsdl/soap/class_def_creator_support.rb +241 -0
- data/vendor/soap4r/wsdl/soap/class_name_creator.rb +55 -0
- data/vendor/soap4r/wsdl/soap/client_skelton_creator.rb +107 -0
- data/vendor/soap4r/wsdl/soap/complex_type.rb +174 -0
- data/vendor/soap4r/wsdl/soap/data.rb +43 -0
- data/vendor/soap4r/wsdl/soap/definitions.rb +201 -0
- data/vendor/soap4r/wsdl/soap/driver_creator.rb +121 -0
- data/vendor/soap4r/wsdl/soap/element.rb +34 -0
- data/vendor/soap4r/wsdl/soap/encoded_mapping_registry_creator.rb +74 -0
- data/vendor/soap4r/wsdl/soap/fault.rb +57 -0
- data/vendor/soap4r/wsdl/soap/header.rb +87 -0
- data/vendor/soap4r/wsdl/soap/headerfault.rb +57 -0
- data/vendor/soap4r/wsdl/soap/literal_mapping_registry_creator.rb +116 -0
- data/vendor/soap4r/wsdl/soap/mapping_registry_creator.rb +59 -0
- data/vendor/soap4r/wsdl/soap/mapping_registry_creator_support.rb +377 -0
- data/vendor/soap4r/wsdl/soap/method_def_creator.rb +200 -0
- data/vendor/soap4r/wsdl/soap/operation.rb +113 -0
- data/vendor/soap4r/wsdl/soap/servant_skelton_creator.rb +92 -0
- data/vendor/soap4r/wsdl/soap/servlet_stub_creator.rb +105 -0
- data/vendor/soap4r/wsdl/soap/standalone_server_stub_creator.rb +101 -0
- data/vendor/soap4r/wsdl/soap/wsdl2ruby.rb +226 -0
- data/vendor/soap4r/wsdl/types.rb +45 -0
- data/vendor/soap4r/wsdl/wsdl.rb +25 -0
- data/vendor/soap4r/wsdl/xml_schema/all.rb +25 -0
- data/vendor/soap4r/wsdl/xml_schema/annotation.rb +35 -0
- data/vendor/soap4r/wsdl/xml_schema/any.rb +62 -0
- data/vendor/soap4r/wsdl/xml_schema/any_attribute.rb +49 -0
- data/vendor/soap4r/wsdl/xml_schema/attribute.rb +105 -0
- data/vendor/soap4r/wsdl/xml_schema/attribute_group.rb +69 -0
- data/vendor/soap4r/wsdl/xml_schema/choice.rb +59 -0
- data/vendor/soap4r/wsdl/xml_schema/complex_content.rb +98 -0
- data/vendor/soap4r/wsdl/xml_schema/complex_extension.rb +120 -0
- data/vendor/soap4r/wsdl/xml_schema/complex_restriction.rb +105 -0
- data/vendor/soap4r/wsdl/xml_schema/complex_type.rb +194 -0
- data/vendor/soap4r/wsdl/xml_schema/content.rb +96 -0
- data/vendor/soap4r/wsdl/xml_schema/data.rb +117 -0
- data/vendor/soap4r/wsdl/xml_schema/element.rb +154 -0
- data/vendor/soap4r/wsdl/xml_schema/enumeration.rb +37 -0
- data/vendor/soap4r/wsdl/xml_schema/fractiondigits.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/group.rb +101 -0
- data/vendor/soap4r/wsdl/xml_schema/import.rb +54 -0
- data/vendor/soap4r/wsdl/xml_schema/import_handler.rb +46 -0
- data/vendor/soap4r/wsdl/xml_schema/importer.rb +103 -0
- data/vendor/soap4r/wsdl/xml_schema/include.rb +49 -0
- data/vendor/soap4r/wsdl/xml_schema/length.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/list.rb +49 -0
- data/vendor/soap4r/wsdl/xml_schema/maxexclusive.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/maxinclusive.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/maxlength.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/minexclusive.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/mininclusive.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/minlength.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/parser.rb +168 -0
- data/vendor/soap4r/wsdl/xml_schema/pattern.rb +37 -0
- data/vendor/soap4r/wsdl/xml_schema/ref.rb +34 -0
- data/vendor/soap4r/wsdl/xml_schema/schema.rb +179 -0
- data/vendor/soap4r/wsdl/xml_schema/sequence.rb +55 -0
- data/vendor/soap4r/wsdl/xml_schema/simple_content.rb +70 -0
- data/vendor/soap4r/wsdl/xml_schema/simple_extension.rb +63 -0
- data/vendor/soap4r/wsdl/xml_schema/simple_restriction.rb +133 -0
- data/vendor/soap4r/wsdl/xml_schema/simple_type.rb +88 -0
- data/vendor/soap4r/wsdl/xml_schema/totaldigits.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/union.rb +36 -0
- data/vendor/soap4r/wsdl/xml_schema/unique.rb +35 -0
- data/vendor/soap4r/wsdl/xml_schema/whitespace.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/xsd2ruby.rb +176 -0
- data/vendor/soap4r/xsd/charset.rb +190 -0
- data/vendor/soap4r/xsd/codegen.rb +13 -0
- data/vendor/soap4r/xsd/codegen/classdef.rb +209 -0
- data/vendor/soap4r/xsd/codegen/commentdef.rb +35 -0
- data/vendor/soap4r/xsd/codegen/gensupport.rb +277 -0
- data/vendor/soap4r/xsd/codegen/methoddef.rb +71 -0
- data/vendor/soap4r/xsd/codegen/moduledef.rb +209 -0
- data/vendor/soap4r/xsd/datatypes.rb +1466 -0
- data/vendor/soap4r/xsd/datatypes1999.rb +21 -0
- data/vendor/soap4r/xsd/iconvcharset.rb +34 -0
- data/vendor/soap4r/xsd/mapping.rb +69 -0
- data/vendor/soap4r/xsd/namedelements.rb +133 -0
- data/vendor/soap4r/xsd/ns.rb +183 -0
- data/vendor/soap4r/xsd/qname.rb +80 -0
- data/vendor/soap4r/xsd/xmlparser.rb +77 -0
- data/vendor/soap4r/xsd/xmlparser/libxmlparser.rb +116 -0
- data/vendor/soap4r/xsd/xmlparser/parser.rb +101 -0
- data/vendor/soap4r/xsd/xmlparser/rexmlparser.rb +59 -0
- data/vendor/soap4r/xsd/xmlparser/xmlparser.rb +51 -0
- data/vendor/soap4r/xsd/xmlparser/xmlscanner.rb +150 -0
- metadata +316 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# XSD4R - XML Instance parser library.
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'xsd/xmlparser/parser'
|
11
|
+
|
12
|
+
|
13
|
+
module XSD
|
14
|
+
|
15
|
+
|
16
|
+
module XMLParser
|
17
|
+
def create_parser(host, opt)
|
18
|
+
XSD::XMLParser::Parser.create_parser(host, opt)
|
19
|
+
end
|
20
|
+
module_function :create_parser
|
21
|
+
|
22
|
+
# $1 is necessary.
|
23
|
+
NSParseRegexp = Regexp.new('^xmlns:?(.*)$', nil, 'n')
|
24
|
+
|
25
|
+
def filter_ns(ns, attrs)
|
26
|
+
ns_updated = false
|
27
|
+
if attrs.nil? or attrs.empty?
|
28
|
+
return [ns, attrs]
|
29
|
+
end
|
30
|
+
newattrs = {}
|
31
|
+
attrs.each do |key, value|
|
32
|
+
if NSParseRegexp =~ key
|
33
|
+
unless ns_updated
|
34
|
+
ns = ns.clone_ns
|
35
|
+
ns_updated = true
|
36
|
+
end
|
37
|
+
# tag == '' means 'default namespace'
|
38
|
+
# value == '' means 'no default namespace'
|
39
|
+
tag = $1 || ''
|
40
|
+
ns.assign(value, tag)
|
41
|
+
else
|
42
|
+
newattrs[key] = value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
return [ns, newattrs]
|
46
|
+
end
|
47
|
+
module_function :filter_ns
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# Try to load XML processor.
|
55
|
+
loaded = false
|
56
|
+
[
|
57
|
+
'nokogiri',
|
58
|
+
# 'libxmlparser',
|
59
|
+
# 'xmlparser',
|
60
|
+
# 'xmlscanner',
|
61
|
+
'rexmlparser',
|
62
|
+
].each do |name|
|
63
|
+
begin
|
64
|
+
require "xsd/xmlparser/#{name}"
|
65
|
+
# XXX: for a workaround of rubygems' require inconsistency
|
66
|
+
# XXX: MUST BE REMOVED IN THE FUTURE
|
67
|
+
raise LoadError unless XSD::XMLParser.constants.find { |c|
|
68
|
+
c.to_s.downcase == name
|
69
|
+
}
|
70
|
+
loaded = true
|
71
|
+
break
|
72
|
+
rescue LoadError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
unless loaded
|
76
|
+
raise RuntimeError.new("XML processor module not found.")
|
77
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# XSD4R - XMLParser XML parser library.
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'xsd/xmlparser'
|
11
|
+
require 'xml/libxml'
|
12
|
+
|
13
|
+
|
14
|
+
module XSD
|
15
|
+
module XMLParser
|
16
|
+
|
17
|
+
|
18
|
+
class LibXMLParser < XSD::XMLParser::Parser
|
19
|
+
include XML::SaxParser::Callbacks
|
20
|
+
|
21
|
+
def do_parse(string_or_readable)
|
22
|
+
if string_or_readable.respond_to?(:read)
|
23
|
+
string = string_or_readable.read
|
24
|
+
else
|
25
|
+
string = string_or_readable
|
26
|
+
end
|
27
|
+
# XMLParser passes a String in utf-8.
|
28
|
+
@charset = 'utf-8'
|
29
|
+
@parser = XML::SaxParser.new
|
30
|
+
@parser.callbacks = self
|
31
|
+
@parser.string = string
|
32
|
+
@parser.parse
|
33
|
+
end
|
34
|
+
|
35
|
+
ENTITY_REF_MAP = {
|
36
|
+
'lt' => '<',
|
37
|
+
'gt' => '>',
|
38
|
+
'amp' => '&',
|
39
|
+
'quot' => '"',
|
40
|
+
'apos' => '\''
|
41
|
+
}
|
42
|
+
|
43
|
+
#def on_internal_subset(name, external_id, system_id)
|
44
|
+
# nil
|
45
|
+
#end
|
46
|
+
|
47
|
+
#def on_is_standalone()
|
48
|
+
# nil
|
49
|
+
#end
|
50
|
+
|
51
|
+
#def on_has_internal_subset()
|
52
|
+
# nil
|
53
|
+
#end
|
54
|
+
|
55
|
+
#def on_has_external_subset()
|
56
|
+
# nil
|
57
|
+
#end
|
58
|
+
|
59
|
+
#def on_start_document()
|
60
|
+
# nil
|
61
|
+
#end
|
62
|
+
|
63
|
+
#def on_end_document()
|
64
|
+
# nil
|
65
|
+
#end
|
66
|
+
|
67
|
+
def on_start_element(name, attr_hash)
|
68
|
+
start_element(name, attr_hash)
|
69
|
+
end
|
70
|
+
|
71
|
+
def on_end_element(name)
|
72
|
+
end_element(name)
|
73
|
+
end
|
74
|
+
|
75
|
+
def on_reference(name)
|
76
|
+
characters(ENTITY_REF_MAP[name])
|
77
|
+
end
|
78
|
+
|
79
|
+
def on_characters(chars)
|
80
|
+
characters(chars)
|
81
|
+
end
|
82
|
+
|
83
|
+
#def on_processing_instruction(target, data)
|
84
|
+
# nil
|
85
|
+
#end
|
86
|
+
|
87
|
+
#def on_comment(msg)
|
88
|
+
# nil
|
89
|
+
#end
|
90
|
+
|
91
|
+
def on_parser_warning(msg)
|
92
|
+
warn(msg)
|
93
|
+
end
|
94
|
+
|
95
|
+
def on_parser_error(msg)
|
96
|
+
raise ParseError.new(msg)
|
97
|
+
end
|
98
|
+
|
99
|
+
def on_parser_fatal_error(msg)
|
100
|
+
raise ParseError.new(msg)
|
101
|
+
end
|
102
|
+
|
103
|
+
def on_cdata_block(cdata)
|
104
|
+
characters(cdata)
|
105
|
+
end
|
106
|
+
|
107
|
+
def on_external_subset(name, external_id, system_id)
|
108
|
+
nil
|
109
|
+
end
|
110
|
+
|
111
|
+
add_factory(self)
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# XSD4R - XML Instance parser library.
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'xsd/qname'
|
11
|
+
require 'xsd/ns'
|
12
|
+
require 'xsd/charset'
|
13
|
+
|
14
|
+
|
15
|
+
module XSD
|
16
|
+
module XMLParser
|
17
|
+
|
18
|
+
|
19
|
+
class Parser
|
20
|
+
class ParseError < Error; end
|
21
|
+
class FormatDecodeError < ParseError; end
|
22
|
+
class UnknownElementError < FormatDecodeError; end
|
23
|
+
class UnknownAttributeError < FormatDecodeError; end
|
24
|
+
class UnexpectedElementError < FormatDecodeError; end
|
25
|
+
class ElementConstraintError < FormatDecodeError; end
|
26
|
+
class ParserError < ParseError; end
|
27
|
+
|
28
|
+
@@parser_factory = nil
|
29
|
+
|
30
|
+
def self.factory
|
31
|
+
@@parser_factory
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.create_parser(host, opt = {})
|
35
|
+
unless @@parser_factory
|
36
|
+
raise ParserError.new("illegal XML parser configuration")
|
37
|
+
end
|
38
|
+
@@parser_factory.new(host, opt)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.add_factory(factory)
|
42
|
+
if $DEBUG
|
43
|
+
puts "Set #{ factory } as XML processor."
|
44
|
+
end
|
45
|
+
@@parser_factory = factory
|
46
|
+
end
|
47
|
+
|
48
|
+
public
|
49
|
+
|
50
|
+
attr_accessor :charset
|
51
|
+
|
52
|
+
def initialize(host, opt = {})
|
53
|
+
@host = host
|
54
|
+
@charset = opt[:charset] || nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse(string_or_readable)
|
58
|
+
@textbuf = ''
|
59
|
+
prologue
|
60
|
+
do_parse(string_or_readable)
|
61
|
+
epilogue
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def do_parse(string_or_readable)
|
67
|
+
raise ParserError.new(
|
68
|
+
'Method do_parse must be defined in derived class.')
|
69
|
+
end
|
70
|
+
|
71
|
+
def start_element(name, attrs)
|
72
|
+
@host.start_element(name, attrs)
|
73
|
+
end
|
74
|
+
|
75
|
+
def characters(text)
|
76
|
+
@host.characters(text)
|
77
|
+
end
|
78
|
+
|
79
|
+
def end_element(name)
|
80
|
+
@host.end_element(name)
|
81
|
+
end
|
82
|
+
|
83
|
+
def prologue
|
84
|
+
end
|
85
|
+
|
86
|
+
def epilogue
|
87
|
+
end
|
88
|
+
|
89
|
+
def xmldecl_encoding=(charset)
|
90
|
+
if @charset.nil?
|
91
|
+
@charset = charset
|
92
|
+
else
|
93
|
+
# Definition in a stream (like HTTP) has a priority.
|
94
|
+
p "encoding definition: #{ charset } is ignored." if $DEBUG
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# XSD4R - REXMLParser XML parser library.
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'xsd/xmlparser'
|
11
|
+
require 'rexml/streamlistener'
|
12
|
+
require 'rexml/document'
|
13
|
+
|
14
|
+
|
15
|
+
module XSD
|
16
|
+
module XMLParser
|
17
|
+
|
18
|
+
|
19
|
+
class REXMLParser < XSD::XMLParser::Parser
|
20
|
+
include REXML::StreamListener
|
21
|
+
|
22
|
+
def do_parse(string_or_readable)
|
23
|
+
source = nil
|
24
|
+
source = REXML::SourceFactory.create_from(string_or_readable)
|
25
|
+
source.encoding = charset if charset
|
26
|
+
# Listener passes a String in utf-8.
|
27
|
+
@charset = 'utf-8'
|
28
|
+
REXML::Document.parse_stream(source, self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def epilogue
|
32
|
+
end
|
33
|
+
|
34
|
+
def tag_start(name, attrs)
|
35
|
+
start_element(name, attrs)
|
36
|
+
end
|
37
|
+
|
38
|
+
def tag_end(name)
|
39
|
+
end_element(name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def text(text)
|
43
|
+
characters(text)
|
44
|
+
end
|
45
|
+
|
46
|
+
def cdata(content)
|
47
|
+
characters(content)
|
48
|
+
end
|
49
|
+
|
50
|
+
def xmldecl(version, encoding, standalone)
|
51
|
+
# Version should be checked.
|
52
|
+
end
|
53
|
+
|
54
|
+
add_factory(self)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# XSD4R - XMLParser XML parser library.
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'xsd/xmlparser'
|
11
|
+
require 'xml/parser'
|
12
|
+
|
13
|
+
|
14
|
+
module XSD
|
15
|
+
module XMLParser
|
16
|
+
|
17
|
+
|
18
|
+
class XMLParser < XSD::XMLParser::Parser
|
19
|
+
class Listener < XML::Parser
|
20
|
+
begin
|
21
|
+
require 'xml/encoding-ja'
|
22
|
+
include XML::Encoding_ja
|
23
|
+
rescue LoadError
|
24
|
+
# uconv may not be installed.
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def do_parse(string_or_readable)
|
29
|
+
# XMLParser passes a String in utf-8.
|
30
|
+
@charset = 'utf-8'
|
31
|
+
@parser = Listener.new
|
32
|
+
@parser.parse(string_or_readable) do |type, name, data|
|
33
|
+
case type
|
34
|
+
when XML::Parser::START_ELEM
|
35
|
+
start_element(name, data)
|
36
|
+
when XML::Parser::END_ELEM
|
37
|
+
end_element(name)
|
38
|
+
when XML::Parser::CDATA
|
39
|
+
characters(data)
|
40
|
+
else
|
41
|
+
raise FormatDecodeError.new("Unexpected XML: #{ type }/#{ name }/#{ data }.")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
add_factory(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# XSD4R - XMLScan XML parser library.
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'xsd/xmlparser'
|
11
|
+
require 'xmlscan/scanner'
|
12
|
+
|
13
|
+
|
14
|
+
module XSD
|
15
|
+
module XMLParser
|
16
|
+
|
17
|
+
|
18
|
+
class XMLScanner < XSD::XMLParser::Parser
|
19
|
+
include XMLScan::Visitor
|
20
|
+
|
21
|
+
def do_parse(string_or_readable)
|
22
|
+
@attrs = {}
|
23
|
+
@curattr = nil
|
24
|
+
@scanner = XMLScan::XMLScanner.new(self)
|
25
|
+
@scanner.kcode = XSD::Charset.charset_str(charset) if charset
|
26
|
+
@scanner.parse(string_or_readable)
|
27
|
+
end
|
28
|
+
|
29
|
+
def scanner_kcode=(charset)
|
30
|
+
@scanner.kcode = XSD::Charset.charset_str(charset) if charset
|
31
|
+
self.xmldecl_encoding = charset
|
32
|
+
end
|
33
|
+
|
34
|
+
ENTITY_REF_MAP = {
|
35
|
+
'lt' => '<',
|
36
|
+
'gt' => '>',
|
37
|
+
'amp' => '&',
|
38
|
+
'quot' => '"',
|
39
|
+
'apos' => '\''
|
40
|
+
}
|
41
|
+
|
42
|
+
def parse_error(msg)
|
43
|
+
raise ParseError.new(msg)
|
44
|
+
end
|
45
|
+
|
46
|
+
def wellformed_error(msg)
|
47
|
+
raise NotWellFormedError.new(msg)
|
48
|
+
end
|
49
|
+
|
50
|
+
def valid_error(msg)
|
51
|
+
raise NotValidError.new(msg)
|
52
|
+
end
|
53
|
+
|
54
|
+
def warning(msg)
|
55
|
+
warn(msg)
|
56
|
+
end
|
57
|
+
|
58
|
+
# def on_xmldecl; end
|
59
|
+
|
60
|
+
def on_xmldecl_version(str)
|
61
|
+
# 1.0 expected.
|
62
|
+
end
|
63
|
+
|
64
|
+
def on_xmldecl_encoding(str)
|
65
|
+
self.scanner_kcode = str
|
66
|
+
end
|
67
|
+
|
68
|
+
# def on_xmldecl_standalone(str); end
|
69
|
+
|
70
|
+
# def on_xmldecl_other(name, value); end
|
71
|
+
|
72
|
+
# def on_xmldecl_end; end
|
73
|
+
|
74
|
+
# def on_doctype(root, pubid, sysid); end
|
75
|
+
|
76
|
+
# def on_prolog_space(str); end
|
77
|
+
|
78
|
+
# def on_comment(str); end
|
79
|
+
|
80
|
+
# def on_pi(target, pi); end
|
81
|
+
|
82
|
+
def on_chardata(str)
|
83
|
+
characters(str)
|
84
|
+
end
|
85
|
+
|
86
|
+
def on_cdata(str)
|
87
|
+
characters(str)
|
88
|
+
end
|
89
|
+
|
90
|
+
def on_etag(name)
|
91
|
+
end_element(name)
|
92
|
+
end
|
93
|
+
|
94
|
+
def on_entityref(ref)
|
95
|
+
characters(ENTITY_REF_MAP[ref])
|
96
|
+
end
|
97
|
+
|
98
|
+
def on_charref(code)
|
99
|
+
characters([code].pack('U'))
|
100
|
+
end
|
101
|
+
|
102
|
+
def on_charref_hex(code)
|
103
|
+
on_charref(code)
|
104
|
+
end
|
105
|
+
|
106
|
+
# def on_start_document; end
|
107
|
+
|
108
|
+
# def on_end_document; end
|
109
|
+
|
110
|
+
def on_stag(name)
|
111
|
+
@attrs = {}
|
112
|
+
end
|
113
|
+
|
114
|
+
def on_attribute(name)
|
115
|
+
@attrs[name] = @curattr = ''
|
116
|
+
end
|
117
|
+
|
118
|
+
def on_attr_value(str)
|
119
|
+
@curattr << str
|
120
|
+
end
|
121
|
+
|
122
|
+
def on_attr_entityref(ref)
|
123
|
+
@curattr << ENTITY_REF_MAP[ref]
|
124
|
+
end
|
125
|
+
|
126
|
+
def on_attr_charref(code)
|
127
|
+
@curattr << [code].pack('U')
|
128
|
+
end
|
129
|
+
|
130
|
+
def on_attr_charref_hex(code)
|
131
|
+
on_attr_charref(code)
|
132
|
+
end
|
133
|
+
|
134
|
+
# def on_attribute_end(name); end
|
135
|
+
|
136
|
+
def on_stag_end_empty(name)
|
137
|
+
on_stag_end(name)
|
138
|
+
on_etag(name)
|
139
|
+
end
|
140
|
+
|
141
|
+
def on_stag_end(name)
|
142
|
+
start_element(name, @attrs)
|
143
|
+
end
|
144
|
+
|
145
|
+
add_factory(self)
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|