multi_xml 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of multi_xml might be problematic. Click here for more details.
- data/.travis.yml +1 -0
- data/Gemfile +2 -1
- data/README.md +30 -35
- data/Rakefile +0 -0
- data/lib/multi_xml.rb +13 -6
- data/lib/multi_xml/parsers/ox.rb +49 -0
- data/lib/multi_xml/version.rb +1 -1
- data/multi_xml.gemspec +8 -10
- data/spec/multi_xml_spec.rb +2 -1
- data/spec/parser_shared_example.rb +2 -0
- metadata +22 -35
- data/.autotest +0 -1
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -2,7 +2,8 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
group :development, :test do
|
4
4
|
gem 'libxml-ruby', "~> 2.0", :require => nil, :platforms => :mri
|
5
|
-
gem 'nokogiri',
|
5
|
+
gem 'nokogiri', "~> 1.4", :require => nil
|
6
|
+
gem 'ox', ["~> 1.2", ">= 1.2.15"], :require => nil
|
6
7
|
end
|
7
8
|
|
8
9
|
gemspec
|
data/README.md
CHANGED
@@ -1,24 +1,20 @@
|
|
1
|
-
MultiXML
|
2
|
-
========
|
1
|
+
# MultiXML
|
3
2
|
A generic swappable back-end for XML parsing
|
4
3
|
|
5
|
-
Installation
|
6
|
-
------------
|
4
|
+
## <a name="installation">Installation</a>
|
7
5
|
gem install multi_xml
|
8
6
|
|
9
|
-
Documentation
|
10
|
-
-------------
|
7
|
+
## <a name="documentation">Documentation</a>
|
11
8
|
[http://rdoc.info/gems/multi_xml](http://rdoc.info/gems/multi_xml)
|
12
9
|
|
13
|
-
Continuous Integration
|
14
|
-
|
15
|
-
[](http://travis-ci.org/sferik/multi_xml)
|
10
|
+
## <a name="ci">Continuous Integration</a>
|
11
|
+
[](http://travis-ci.org/sferik/multi_xml)
|
16
12
|
|
17
|
-
Usage Examples
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
## <a name="examples">Usage Examples</a>
|
14
|
+
Lots of Ruby libraries utilize XML parsing in some form, and everyone has their
|
15
|
+
favorite XML library. In order to best support multiple XML parsers and
|
16
|
+
libraries, <tt>multi_xml</tt> is a general-purpose swappable XML backend
|
17
|
+
library. You use it like so:
|
22
18
|
|
23
19
|
require 'multi_xml'
|
24
20
|
|
@@ -41,9 +37,10 @@ MultiXML tries to have intelligent defaulting. That is, if you have any of the s
|
|
41
37
|
already loaded, it will utilize them before attempting to load any. When loading, libraries are
|
42
38
|
ordered by speed: first LibXML, then Nokogiri, then REXML.
|
43
39
|
|
44
|
-
Contributing
|
45
|
-
|
46
|
-
|
40
|
+
## <a name="contributing">Contributing</a>
|
41
|
+
In the spirit of [free
|
42
|
+
software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is
|
43
|
+
encouraged to help improve this project.
|
47
44
|
|
48
45
|
Here are some ways *you* can contribute:
|
49
46
|
|
@@ -57,17 +54,17 @@ Here are some ways *you* can contribute:
|
|
57
54
|
* by resolving [issues](https://github.com/sferik/multi_xml/issues)
|
58
55
|
* by reviewing patches
|
59
56
|
|
60
|
-
Submitting an Issue
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
details that may be necessary to reproduce the bug, including your gem version,
|
67
|
-
operating system. Ideally, a bug report should include a pull
|
68
|
-
|
69
|
-
|
70
|
-
|
57
|
+
## <a name="issues">Submitting an Issue</a>
|
58
|
+
We use the [GitHub issue tracker](https://github.com/sferik/multi_xml/issues)
|
59
|
+
to track bugs and features. Before submitting a bug report or feature request,
|
60
|
+
check to make sure it hasn't already been submitted. You can indicate support
|
61
|
+
for an existing issuse by voting it up. When submitting a bug report, please
|
62
|
+
include a [Gist](https://gist.github.com/) that includes a stack trace and any
|
63
|
+
details that may be necessary to reproduce the bug, including your gem version,
|
64
|
+
Ruby version, and operating system. Ideally, a bug report should include a pull
|
65
|
+
request with failing specs.
|
66
|
+
|
67
|
+
## <a name="pulls">Submitting a Pull Request</a>
|
71
68
|
1. Fork the project.
|
72
69
|
2. Create a topic branch.
|
73
70
|
3. Implement your feature or bug fix.
|
@@ -78,8 +75,7 @@ Submitting a Pull Request
|
|
78
75
|
8. Commit and push your changes.
|
79
76
|
9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
|
80
77
|
|
81
|
-
Supported Rubies
|
82
|
-
----------------
|
78
|
+
## <a name="rubies">Supported Rubies</a>
|
83
79
|
This library aims to support and is [tested
|
84
80
|
against](http://travis-ci.org/sferik/multi_xml) the following Ruby
|
85
81
|
implementations:
|
@@ -87,7 +83,8 @@ implementations:
|
|
87
83
|
* Ruby 1.8.7
|
88
84
|
* Ruby 1.9.1
|
89
85
|
* Ruby 1.9.2
|
90
|
-
* [
|
86
|
+
* [JRuby](http://www.jruby.org/)
|
87
|
+
* [Rubinius](http://rubini.us/)
|
91
88
|
* [Ruby Enterprise Edition](http://www.rubyenterpriseedition.com/)
|
92
89
|
|
93
90
|
If something doesn't work on one of these interpreters, it should be considered
|
@@ -104,11 +101,9 @@ implementation, you will be personally responsible for providing patches in a
|
|
104
101
|
timely fashion. If critical issues for a particular implementation exist at the
|
105
102
|
time of a major release, support for that Ruby version may be dropped.
|
106
103
|
|
107
|
-
Inspiration
|
108
|
-
-----------
|
104
|
+
## <a name="inspiration">Inspiration</a>
|
109
105
|
MultiXML was inspired by [MultiJSON](https://github.com/intridea/multi_json/).
|
110
106
|
|
111
|
-
Copyright
|
112
|
-
---------
|
107
|
+
## <a name="copyright">Copyright</a>
|
113
108
|
Copyright (c) 2010 Erik Michaels-Ober.
|
114
109
|
See [LICENSE](https://github.com/sferik/multi_xml/blob/master/LICENSE.md) for details.
|
data/Rakefile
CHANGED
File without changes
|
data/lib/multi_xml.rb
CHANGED
@@ -11,6 +11,7 @@ module MultiXml
|
|
11
11
|
REQUIREMENT_MAP = [
|
12
12
|
['libxml', :libxml],
|
13
13
|
['nokogiri', :nokogiri],
|
14
|
+
['ox', :ox],
|
14
15
|
['rexml/document', :rexml]
|
15
16
|
] unless defined?(REQUIREMENT_MAP)
|
16
17
|
|
@@ -71,6 +72,7 @@ module MultiXml
|
|
71
72
|
#
|
72
73
|
# * <tt>:libxml</tt>
|
73
74
|
# * <tt>:nokogiri</tt>
|
75
|
+
# * <tt>:ox</tt>
|
74
76
|
# * <tt>:rexml</tt>
|
75
77
|
def parser=(new_parser)
|
76
78
|
case new_parser
|
@@ -94,14 +96,19 @@ module MultiXml
|
|
94
96
|
|
95
97
|
xml.strip! if xml.respond_to?(:strip!)
|
96
98
|
|
97
|
-
|
99
|
+
begin
|
100
|
+
if parser.respond_to?(:string_parser?) and parser.string_parser?
|
101
|
+
raw_hash = parser.parse(xml)
|
102
|
+
else
|
103
|
+
xml = StringIO.new(xml) unless xml.respond_to?(:read)
|
98
104
|
|
99
|
-
|
100
|
-
|
101
|
-
|
105
|
+
char = xml.getc
|
106
|
+
return {} if char.nil?
|
107
|
+
xml.ungetc(char)
|
102
108
|
|
103
|
-
|
104
|
-
|
109
|
+
raw_hash = parser.parse(xml)
|
110
|
+
end
|
111
|
+
hash = typecast_xml_value(undasherize_keys(raw_hash)) || {}
|
105
112
|
rescue parser.parse_error => error
|
106
113
|
raise ParseError, error.to_s, error.backtrace
|
107
114
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'ox' unless defined?(Ox)
|
2
|
+
|
3
|
+
module MultiXml
|
4
|
+
module Parsers
|
5
|
+
module Ox #:nodoc:
|
6
|
+
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def parse_error
|
10
|
+
Exception
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse(xml)
|
14
|
+
doc = ::Ox.parse(xml)
|
15
|
+
h = { }
|
16
|
+
element_to_hash(doc, h) unless doc.nil?
|
17
|
+
h
|
18
|
+
end
|
19
|
+
|
20
|
+
def element_to_hash(e, h)
|
21
|
+
content = { }
|
22
|
+
e.attributes.each do |k,v|
|
23
|
+
content[k.to_s] = v
|
24
|
+
end
|
25
|
+
e.nodes.each do |n|
|
26
|
+
if n.is_a?(::Ox::Element)
|
27
|
+
element_to_hash(n, content)
|
28
|
+
elsif n.is_a?(String)
|
29
|
+
content['__content__'] = n
|
30
|
+
elsif n.is_a?(::Ox::Node)
|
31
|
+
content['__content__'] = n.value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
if (ex = h[e.name]).nil?
|
35
|
+
h[e.name] = content
|
36
|
+
elsif ex.is_a?(Array)
|
37
|
+
ex << content
|
38
|
+
else
|
39
|
+
h[e.name] = [ex, content]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def string_parser?
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/multi_xml/version.rb
CHANGED
data/multi_xml.gemspec
CHANGED
@@ -1,24 +1,22 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
require File.expand_path('../lib/multi_xml/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.add_development_dependency 'ZenTest', '~> 4.5'
|
6
|
-
gem.add_development_dependency 'maruku', '~> 0.6'
|
7
5
|
gem.add_development_dependency 'nokogiri', '~> 1.4'
|
8
6
|
gem.add_development_dependency 'rake', '~> 0.9'
|
7
|
+
gem.add_development_dependency 'rdiscount', '~> 1.6'
|
9
8
|
gem.add_development_dependency 'rspec', '~> 2.6'
|
10
9
|
gem.add_development_dependency 'simplecov', '~> 0.4'
|
11
10
|
gem.add_development_dependency 'yard', '~> 0.7'
|
12
|
-
gem.name = 'multi_xml'
|
13
|
-
gem.version = MultiXml::VERSION
|
14
|
-
gem.platform = Gem::Platform::RUBY
|
15
11
|
gem.author = "Erik Michaels-Ober"
|
12
|
+
gem.description = %q{A gem to provide swappable XML backends utilizing LibXML, Nokogiri, or REXML.}
|
16
13
|
gem.email = '[email protected]'
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
17
15
|
gem.homepage = 'https://github.com/sferik/multi_xml'
|
16
|
+
gem.name = 'multi_xml'
|
17
|
+
gem.platform = Gem::Platform::RUBY
|
18
|
+
gem.require_paths = ['lib']
|
18
19
|
gem.summary = %q{A generic swappable back-end for XML parsing}
|
19
|
-
gem.description = %q{A gem to provide swappable XML backends utilizing LibXML, Nokogiri, or REXML.}
|
20
|
-
gem.files = `git ls-files`.split("\n")
|
21
20
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
-
gem.
|
23
|
-
gem.require_paths = ['lib']
|
21
|
+
gem.version = MultiXml::VERSION
|
24
22
|
end
|
data/spec/multi_xml_spec.rb
CHANGED
@@ -27,7 +27,8 @@ describe "MultiXml" do
|
|
27
27
|
|
28
28
|
[['LibXML', 'libxml'],
|
29
29
|
['REXML', 'rexml/document'],
|
30
|
-
['Nokogiri', 'nokogiri']
|
30
|
+
['Nokogiri', 'nokogiri'],
|
31
|
+
['Ox', 'ox']].each do |parser|
|
31
32
|
begin
|
32
33
|
require parser.last
|
33
34
|
context "#{parser.first} parser" do
|
@@ -454,6 +454,7 @@ shared_examples_for "a parser" do |parser|
|
|
454
454
|
end
|
455
455
|
end
|
456
456
|
|
457
|
+
|
457
458
|
context "with dasherized tag" do
|
458
459
|
before do
|
459
460
|
@xml = '<tag-1/>'
|
@@ -544,6 +545,7 @@ shared_examples_for "a parser" do |parser|
|
|
544
545
|
MultiXml.parse(@xml).should == {"users" => {"user" => ["Erik Michaels-Ober", "Wynn Netherland"]}}
|
545
546
|
end
|
546
547
|
end
|
548
|
+
|
547
549
|
end
|
548
550
|
end
|
549
551
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,56 +9,44 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-09-06 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement: &
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ~>
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '4.5'
|
23
|
-
type: :development
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: *70225559600760
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: maruku
|
28
|
-
requirement: &70225559600260 !ruby/object:Gem::Requirement
|
15
|
+
name: nokogiri
|
16
|
+
requirement: &70174632551180 !ruby/object:Gem::Requirement
|
29
17
|
none: false
|
30
18
|
requirements:
|
31
19
|
- - ~>
|
32
20
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
21
|
+
version: '1.4'
|
34
22
|
type: :development
|
35
23
|
prerelease: false
|
36
|
-
version_requirements: *
|
24
|
+
version_requirements: *70174632551180
|
37
25
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
requirement: &
|
26
|
+
name: rake
|
27
|
+
requirement: &70174632547160 !ruby/object:Gem::Requirement
|
40
28
|
none: false
|
41
29
|
requirements:
|
42
30
|
- - ~>
|
43
31
|
- !ruby/object:Gem::Version
|
44
|
-
version: '
|
32
|
+
version: '0.9'
|
45
33
|
type: :development
|
46
34
|
prerelease: false
|
47
|
-
version_requirements: *
|
35
|
+
version_requirements: *70174632547160
|
48
36
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
50
|
-
requirement: &
|
37
|
+
name: rdiscount
|
38
|
+
requirement: &70174632529880 !ruby/object:Gem::Requirement
|
51
39
|
none: false
|
52
40
|
requirements:
|
53
41
|
- - ~>
|
54
42
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
43
|
+
version: '1.6'
|
56
44
|
type: :development
|
57
45
|
prerelease: false
|
58
|
-
version_requirements: *
|
46
|
+
version_requirements: *70174632529880
|
59
47
|
- !ruby/object:Gem::Dependency
|
60
48
|
name: rspec
|
61
|
-
requirement: &
|
49
|
+
requirement: &70174632527760 !ruby/object:Gem::Requirement
|
62
50
|
none: false
|
63
51
|
requirements:
|
64
52
|
- - ~>
|
@@ -66,10 +54,10 @@ dependencies:
|
|
66
54
|
version: '2.6'
|
67
55
|
type: :development
|
68
56
|
prerelease: false
|
69
|
-
version_requirements: *
|
57
|
+
version_requirements: *70174632527760
|
70
58
|
- !ruby/object:Gem::Dependency
|
71
59
|
name: simplecov
|
72
|
-
requirement: &
|
60
|
+
requirement: &70174632526060 !ruby/object:Gem::Requirement
|
73
61
|
none: false
|
74
62
|
requirements:
|
75
63
|
- - ~>
|
@@ -77,10 +65,10 @@ dependencies:
|
|
77
65
|
version: '0.4'
|
78
66
|
type: :development
|
79
67
|
prerelease: false
|
80
|
-
version_requirements: *
|
68
|
+
version_requirements: *70174632526060
|
81
69
|
- !ruby/object:Gem::Dependency
|
82
70
|
name: yard
|
83
|
-
requirement: &
|
71
|
+
requirement: &70174632525380 !ruby/object:Gem::Requirement
|
84
72
|
none: false
|
85
73
|
requirements:
|
86
74
|
- - ~>
|
@@ -88,7 +76,7 @@ dependencies:
|
|
88
76
|
version: '0.7'
|
89
77
|
type: :development
|
90
78
|
prerelease: false
|
91
|
-
version_requirements: *
|
79
|
+
version_requirements: *70174632525380
|
92
80
|
description: A gem to provide swappable XML backends utilizing LibXML, Nokogiri, or
|
93
81
|
REXML.
|
94
82
|
email: [email protected]
|
@@ -96,7 +84,6 @@ executables: []
|
|
96
84
|
extensions: []
|
97
85
|
extra_rdoc_files: []
|
98
86
|
files:
|
99
|
-
- .autotest
|
100
87
|
- .gemtest
|
101
88
|
- .gitignore
|
102
89
|
- .rspec
|
@@ -110,13 +97,13 @@ files:
|
|
110
97
|
- lib/multi_xml/parsers/libxml.rb
|
111
98
|
- lib/multi_xml/parsers/libxml2_parser.rb
|
112
99
|
- lib/multi_xml/parsers/nokogiri.rb
|
100
|
+
- lib/multi_xml/parsers/ox.rb
|
113
101
|
- lib/multi_xml/parsers/rexml.rb
|
114
102
|
- lib/multi_xml/version.rb
|
115
103
|
- multi_xml.gemspec
|
116
104
|
- spec/helper.rb
|
117
105
|
- spec/multi_xml_spec.rb
|
118
106
|
- spec/parser_shared_example.rb
|
119
|
-
has_rdoc: true
|
120
107
|
homepage: https://github.com/sferik/multi_xml
|
121
108
|
licenses: []
|
122
109
|
post_install_message:
|
@@ -137,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
124
|
version: '0'
|
138
125
|
requirements: []
|
139
126
|
rubyforge_project:
|
140
|
-
rubygems_version: 1.
|
127
|
+
rubygems_version: 1.8.10
|
141
128
|
signing_key:
|
142
129
|
specification_version: 3
|
143
130
|
summary: A generic swappable back-end for XML parsing
|
data/.autotest
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'autotest/bundler'
|