xml-simple 1.0.8 → 1.0.9

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.
Files changed (2) hide show
  1. data/lib/xmlsimple.rb +21 -19
  2. metadata +4 -3
@@ -11,7 +11,7 @@ require 'stringio'
11
11
  class XmlSimple
12
12
  include REXML
13
13
 
14
- @@VERSION = '1.0.8'
14
+ @@VERSION = '1.0.9'
15
15
 
16
16
  # A simple cache for XML documents that were already transformed
17
17
  # by xml_in.
@@ -267,7 +267,7 @@ class XmlSimple
267
267
  keyattr keeproot forcecontent contentkey noattr
268
268
  searchpath forcearray suppressempty anonymoustag
269
269
  cache grouptags normalisespace normalizespace
270
- variables varattr
270
+ variables varattr keytosymbol
271
271
  ),
272
272
  'out' => %w(
273
273
  keyattr keeproot contentkey noattr rootname
@@ -284,6 +284,7 @@ class XmlSimple
284
284
  DEF_ANONYMOUS_TAG = 'anon'
285
285
  DEF_FORCE_ARRAY = true
286
286
  DEF_INDENTATION = ' '
287
+ DEF_KEY_TO_SYMBOL = false
287
288
 
288
289
  # Normalizes option names in a hash, i.e., turns all
289
290
  # characters to lower case and removes all underscores.
@@ -351,6 +352,8 @@ class XmlSimple
351
352
  @options['xmldeclaration'] = DEF_XML_DECLARATION
352
353
  end
353
354
 
355
+ @options['keytosymbol'] = DEF_KEY_TO_SYMBOL unless @options.has_key?('keytosymbol')
356
+
354
357
  if @options.has_key?('contentkey')
355
358
  if @options['contentkey'] =~ /^-(.*)$/
356
359
  @options['contentkey'] = $1
@@ -655,6 +658,14 @@ class XmlSimple
655
658
  end
656
659
  end
657
660
  end
661
+
662
+ #patch for converting keys to symbols
663
+ if @options.has_key?('keytosymbol')
664
+ if @options['keytosymbol'] == true
665
+ key = key.to_s.downcase.to_sym
666
+ end
667
+ end
668
+
658
669
  if hash.has_key?(key)
659
670
  if hash[key].instance_of?(Array)
660
671
  hash[key] << value
@@ -880,14 +891,7 @@ class XmlSimple
880
891
  # data::
881
892
  # The string to be escaped.
882
893
  def escape_value(data)
883
- return data if data.nil? || data == ''
884
- result = data.dup
885
- result.gsub!('&', '&amp;')
886
- result.gsub!('<', '&lt;')
887
- result.gsub!('>', '&gt;')
888
- result.gsub!('"', '&quot;')
889
- result.gsub!("'", '&apos;')
890
- result
894
+ Text::normalize(data)
891
895
  end
892
896
 
893
897
  # Removes leading and trailing whitespace and sequences of
@@ -896,10 +900,7 @@ class XmlSimple
896
900
  # text::
897
901
  # String to be normalised.
898
902
  def normalise_space(text)
899
- text.sub!(/^\s+/, '')
900
- text.sub!(/\s+$/, '')
901
- text.gsub!(/\s\s+/, ' ')
902
- text
903
+ text.strip.gsub(/\s\s+/, ' ')
903
904
  end
904
905
 
905
906
  # Checks, if an object is nil, an empty String or an empty Hash.
@@ -927,15 +928,16 @@ class XmlSimple
927
928
  # default::
928
929
  # Value to be returned, if node could not be converted.
929
930
  def node_to_text(node, default = nil)
930
- if node.instance_of?(Element)
931
- return node.texts.join('')
931
+ result = if node.instance_of?(Element)
932
+ node.texts.join('')
932
933
  elsif node.instance_of?(Attribute)
933
- return node.value.nil? ? default : node.value.strip
934
+ node.value.nil? ? default : node.value.strip
934
935
  elsif node.instance_of?(Text)
935
- return node.to_s.strip
936
+ node.to_s.strip
936
937
  else
937
- return default
938
+ default
938
939
  end
940
+ Text::unnormalize(result)
939
941
  end
940
942
 
941
943
  # Parses an XML string and returns the according document.
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: xml-simple
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.8
7
- date: 2006-02-13 00:00:00 +01:00
6
+ version: 1.0.9
7
+ date: 2006-07-02 00:00:00 +02:00
8
8
  summary: A very simple API for XML processing.
9
9
  require_paths:
10
10
  - lib
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Maik Schmidt
30
31
  files: