xml-simple 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/xmlsimple.rb +20 -13
  2. metadata +38 -31
@@ -1,7 +1,7 @@
1
1
  # = XmlSimple
2
2
  #
3
3
  # Author:: Maik Schmidt <contact@maik-schmidt.de>
4
- # Copyright:: Copyright (c) 2003-2006 Maik Schmidt
4
+ # Copyright:: Copyright (c) 2003-2009 Maik Schmidt
5
5
  # License:: Distributes under the same terms as Ruby.
6
6
  #
7
7
  require 'rexml/document'
@@ -11,7 +11,7 @@ require 'stringio'
11
11
  class XmlSimple
12
12
  include REXML
13
13
 
14
- @@VERSION = '1.0.11'
14
+ @@VERSION = '1.0.12'
15
15
 
16
16
  # A simple cache for XML documents that were already transformed
17
17
  # by xml_in.
@@ -151,7 +151,7 @@ class XmlSimple
151
151
 
152
152
  # If no XML string or filename was supplied look for scriptname.xml.
153
153
  if string.nil?
154
- string = File::basename($0)
154
+ string = File::basename($0).dup
155
155
  string.sub!(/\.[^.]+$/, '')
156
156
  string += '.xml'
157
157
 
@@ -163,7 +163,7 @@ class XmlSimple
163
163
  if string =~ /<.*?>/m
164
164
  @doc = parse(string)
165
165
  elsif string == '-'
166
- @doc = parse($stdin.readlines.to_s)
166
+ @doc = parse($stdin.read)
167
167
  else
168
168
  filename = find_xml_file(string, @options['searchpath'])
169
169
 
@@ -185,8 +185,8 @@ class XmlSimple
185
185
 
186
186
  @doc = load_xml_file(filename)
187
187
  end
188
- elsif string.kind_of?(IO) || string.kind_of?(StringIO)
189
- @doc = parse(string.readlines.to_s)
188
+ elsif string.kind_of?(IO) || string.kind_of?(StringIO) || string.kind_of?(Zlib::GzipReader)
189
+ @doc = parse(string.read)
190
190
  else
191
191
  raise ArgumentError, "Could not parse object of type: <#{string.type}>."
192
192
  end
@@ -267,12 +267,12 @@ class XmlSimple
267
267
  keyattr keeproot forcecontent contentkey noattr
268
268
  searchpath forcearray suppressempty anonymoustag
269
269
  cache grouptags normalisespace normalizespace
270
- variables varattr keytosymbol
270
+ variables varattr keytosymbol attrprefix
271
271
  ),
272
272
  'out' => %w(
273
273
  keyattr keeproot contentkey noattr rootname
274
274
  xmldeclaration outputfile noescape suppressempty
275
- anonymoustag indent grouptags noindent
275
+ anonymoustag indent grouptags noindent attrprefix
276
276
  )
277
277
  }
278
278
 
@@ -497,7 +497,7 @@ class XmlSimple
497
497
  }
498
498
  end
499
499
 
500
- # Fold Hases containing a single anonymous Array up into just the Array.
500
+ # Fold Hashes containing a single anonymous Array up into just the Array.
501
501
  if count == 1
502
502
  anonymoustag = @options['anonymoustag']
503
503
  if result.has_key?(anonymoustag) && result[anonymoustag].instance_of?(Array)
@@ -705,7 +705,11 @@ class XmlSimple
705
705
  # Document node to extract attributes from.
706
706
  def get_attributes(node)
707
707
  attributes = {}
708
- node.attributes.each { |n,v| attributes[n] = v }
708
+ if @options['attrprefix']
709
+ node.attributes.each { |n,v| attributes["@" + n] = v }
710
+ else
711
+ node.attributes.each { |n,v| attributes[n] = v }
712
+ end
709
713
  attributes
710
714
  end
711
715
 
@@ -796,7 +800,10 @@ class XmlSimple
796
800
  value = {}
797
801
  end
798
802
 
799
- if !scalar(value) || @options['noattr']
803
+ # Check for the '@' attribute prefix to allow separation of attributes and elements
804
+ if @options['noattr'] ||
805
+ (@options['attrprefix'] && !(key =~ /^@(.*)/)) ||
806
+ !scalar(value)
800
807
  nested << value_to_xml(value, key, indent + @options['indent'])
801
808
  else
802
809
  value = value.to_s
@@ -804,7 +811,7 @@ class XmlSimple
804
811
  if key == @options['contentkey']
805
812
  text_content = value
806
813
  else
807
- result << ' ' << key << '="' << value << '"'
814
+ result << ' ' << ($1||key) << '="' << value << '"'
808
815
  end
809
816
  end
810
817
  }
@@ -991,7 +998,7 @@ class XmlSimple
991
998
  # REXML::ParseException::
992
999
  # If the specified file is not wellformed.
993
1000
  def load_xml_file(filename)
994
- parse(File.readlines(filename).to_s)
1001
+ parse(IO::read(filename))
995
1002
  end
996
1003
 
997
1004
  # Caches the data belonging to a certain file.
metadata CHANGED
@@ -1,46 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: xml-simple
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.0.11
7
- date: 2007-03-12 00:00:00 +01:00
8
- summary: A very simple API for XML processing.
9
- require_paths:
10
- - lib
11
- email: contact@maik-schmidt.de
12
- homepage: http://xml-simple.rubyforge.org
13
- rubyforge_project: xml-simple
14
- description:
15
- autorequire: xmlsimple
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 1.0.12
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Maik Schmidt
31
- files:
32
- - lib/xmlsimple.rb
33
- test_files: []
34
-
35
- rdoc_options: []
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
36
11
 
37
- extra_rdoc_files: []
12
+ date: 2009-02-27 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
38
15
 
16
+ description:
17
+ email: contact@maik-schmidt.de
39
18
  executables: []
40
19
 
41
20
  extensions: []
42
21
 
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/xmlsimple.rb
26
+ has_rdoc: false
27
+ homepage: http://xml-simple.rubyforge.org
28
+ post_install_message:
29
+ rdoc_options: []
30
+
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: "0"
38
+ version:
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
43
45
  requirements: []
44
46
 
45
- dependencies: []
47
+ rubyforge_project: xml-simple
48
+ rubygems_version: 1.3.1
49
+ signing_key:
50
+ specification_version: 2
51
+ summary: A simple API for XML processing.
52
+ test_files: []
46
53