saxerator 0.9.0 → 0.9.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f658aac7bdee282fb08e3b58640872e85736a2b
4
- data.tar.gz: 59155cc7dfd7a43d3427fe2caa051a56bbf8b4d7
3
+ metadata.gz: 549f3904273d8c16502ac451896f49fe49e8425a
4
+ data.tar.gz: 0170f3915d36acbf25f77b6abf6b06dddff8ba8c
5
5
  SHA512:
6
- metadata.gz: 78ced56c7b227e0eca9286e70653bbc4301e838ce944be43f8d6864c29139b8b02546b35108dee6bb655a284aa28c80e341efbcd56820c6c9e1577dadaa29607
7
- data.tar.gz: 41987c42a7ade852213f0c63b5ede55e1a832432c30943bac211fe36bcc76fe3fadda3ff5d4b06625103075963b61c0ff96589691f869f906549589d3da92991
6
+ metadata.gz: 5083fbc22ec09116b79cbb5dbf2c334551e1d2a6448bab12b559aa14feb601fccc33a5caee4a8bf2911131c9e5399a52272869fa5d5d9d69a36ebc2c7a3fd645
7
+ data.tar.gz: d4a324588e410486255f1336d37585410b67ca1b43a078971698b9081cdab3f39c4aa979e35f0abddf4de233bcccb850988cfc174d6fcf2ef94755155313b8f7
data/README.md CHANGED
@@ -92,7 +92,8 @@ end
92
92
  |:------------------|:--------|-----------------|------------
93
93
  | `output_type` | `:hash` | `:hash`, `:xml` | The type of object generated by Saxerator's parsing. `:hash` should be self-explanatory, `:xml` generates a `Nokogiri::XML::Document`
94
94
  | `symbolize_keys!` | n/a | n/a | Call this method if you want the hash keys to be symbols rather than strings
95
- | `strip_namespaces!| n/a | user-specified | Called with no arguments this strips all namespaces, or you may specify an arbitrary number of namespaces to strip, i.e. `config.strip_namespaces! :rss, :soapenv`
95
+ | `ignore_namespaces!`| n/a | n/a | Call this method if you want to treat the XML document as if it has no namespace information. It differs slightly from `strip_namespaces!` since it deals with how the XML is processed rather than how it is output
96
+ | `strip_namespaces!`| n/a | user-specified | Called with no arguments this strips all namespaces, or you may specify an arbitrary number of namespaces to strip, i.e. `config.strip_namespaces! :rss, :soapenv`
96
97
  | `put_attributes_in_hash!` | n/a | n/a | Call this method if you want xml attributes included as elements of the output hash - only valid with `output_type = :hash`
97
98
 
98
99
  Known Issues
@@ -6,6 +6,7 @@ module Saxerator
6
6
  def initialize
7
7
  @output_type = :hash
8
8
  @put_attributes_in_hash = false
9
+ @ignore_namespaces = false
9
10
  end
10
11
 
11
12
  def output_type=(val)
@@ -39,6 +40,14 @@ module Saxerator
39
40
  end
40
41
  end
41
42
 
43
+ def ignore_namespaces?
44
+ @ignore_namespaces
45
+ end
46
+
47
+ def ignore_namespaces!
48
+ @ignore_namespaces = true
49
+ end
50
+
42
51
  def put_attributes_in_hash!
43
52
  @put_attributes_in_hash = true
44
53
  raise_error_if_using_put_attributes_in_hash_with_xml
@@ -4,6 +4,7 @@ module Saxerator
4
4
  def initialize(config, latches, block)
5
5
  @latches = latches
6
6
  @accumulator = Accumulator.new(config, block)
7
+ @ignore_namespaces = config.ignore_namespaces?
7
8
  end
8
9
 
9
10
  def check_latches_and_passthrough(method, *args)
@@ -35,10 +36,12 @@ module Saxerator
35
36
  end
36
37
 
37
38
  def start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = [])
39
+ return start_element(name, attrs) if @ignore_namespaces
38
40
  check_latches_and_passthrough(:start_element_namespace, name, attrs, prefix, uri, ns)
39
41
  end
40
42
 
41
43
  def end_element_namespace(name, prefix = nil, uri = nil)
44
+ return end_element(name) if @ignore_namespaces
42
45
  check_latches_and_passthrough(:end_element_namespace, name, prefix, uri)
43
46
  end
44
47
 
@@ -1,3 +1,3 @@
1
1
  module Saxerator
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -65,6 +65,22 @@ describe Saxerator do
65
65
  specify { parser.all.name.should == :foo }
66
66
  end
67
67
 
68
+ context "with ignore namespaces" do
69
+ let(:xml) { "<ns1:foo xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:ns1=\"http://foo.com\" xmlns:ns3=\"http://bar.com\"><ns3:bar>baz</ns3:bar></ns1:foo>" }
70
+ subject(:parser) do
71
+ Saxerator.parser(xml) { |config| config.ignore_namespaces! }
72
+ end
73
+
74
+ specify {
75
+ bar_count = 0
76
+ parser.for_tag("bar").each do |tag|
77
+ bar_count += 1
78
+ end
79
+
80
+ bar_count.should == 1
81
+ }
82
+ end
83
+
68
84
  context "with strip namespaces" do
69
85
  let(:xml) { "<ns1:foo><ns3:bar>baz</ns3:bar></ns1:foo>" }
70
86
  subject(:parser) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saxerator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bradley Schaefer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-30 00:00:00.000000000 Z
11
+ date: 2014-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -47,19 +47,21 @@ executables: []
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
+ - .gitignore
51
+ - .travis.yml
52
+ - Gemfile
50
53
  - LICENSE
51
54
  - README.md
52
- - saxerator.gemspec
53
- - Gemfile
54
55
  - Rakefile
55
- - .gitignore
56
- - .travis.yml
56
+ - benchmark/benchmark.rb
57
+ - benchmark/generate_sample_file.rb
58
+ - lib/saxerator.rb
59
+ - lib/saxerator/builder.rb
57
60
  - lib/saxerator/builder/array_element.rb
58
61
  - lib/saxerator/builder/hash_builder.rb
59
62
  - lib/saxerator/builder/hash_element.rb
60
63
  - lib/saxerator/builder/string_element.rb
61
64
  - lib/saxerator/builder/xml_builder.rb
62
- - lib/saxerator/builder.rb
63
65
  - lib/saxerator/configuration.rb
64
66
  - lib/saxerator/document_fragment.rb
65
67
  - lib/saxerator/dsl.rb
@@ -73,7 +75,7 @@ files:
73
75
  - lib/saxerator/parser/accumulator.rb
74
76
  - lib/saxerator/parser/latched_accumulator.rb
75
77
  - lib/saxerator/version.rb
76
- - lib/saxerator.rb
78
+ - saxerator.gemspec
77
79
  - spec/fixtures/flat_blurbs.xml
78
80
  - spec/fixtures/nested_elements.xml
79
81
  - spec/lib/builder/hash_builder_spec.rb
@@ -89,8 +91,6 @@ files:
89
91
  - spec/lib/saxerator_spec.rb
90
92
  - spec/spec_helper.rb
91
93
  - spec/support/fixture_file.rb
92
- - benchmark/benchmark.rb
93
- - benchmark/generate_sample_file.rb
94
94
  homepage: https://github.com/soulcutter/saxerator
95
95
  licenses:
96
96
  - MIT
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project: saxerator
114
- rubygems_version: 2.0.3
114
+ rubygems_version: 2.2.2
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: A SAX-based XML-to-hash parser for parsing large files into manageable chunks