rexle 0.9.64 → 0.9.65

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/rexle.rb +17 -7
  2. metadata +2 -2
data/lib/rexle.rb CHANGED
@@ -10,8 +10,9 @@ require 'cgi'
10
10
  include REXML
11
11
 
12
12
  # modifications:
13
+ # 10-Nov-2012: Elements can now be added starting from an empty document
13
14
  # 06-Nov-2012: additional xpath predicate now implemented e.g.
14
- # fun/. > 200 => [false, false, true, true]
15
+ # fun/. > 200 => [false, false, true, true]
15
16
  # 21-Oct-2012: xpath predicate now implemented e.g. fun/@id='4' => true
16
17
  # 20-Oct-2012: feature: added Rexle::Element#texts which is the equivalent
17
18
  # of REXML::Element#texts
@@ -124,12 +125,9 @@ class Rexle
124
125
  include XMLhelper
125
126
 
126
127
  attr_reader :prefixes
127
-
128
- def self.version()
129
- '0.9.xx'
130
- end
131
128
 
132
129
  def initialize(x=nil)
130
+
133
131
  super()
134
132
 
135
133
  # what type of input is it? Is it a string, array, or REXML doc?
@@ -153,7 +151,7 @@ class Rexle
153
151
  xmlns = @doc.root.attributes.select {|k,v| k[/^xmlns:/]}
154
152
  @prefixes = xmlns.keys.map{|x| x[/\w+$/]}
155
153
  end
156
-
154
+
157
155
  end
158
156
 
159
157
  end
@@ -407,6 +405,7 @@ class Rexle
407
405
 
408
406
  def add_element(item)
409
407
  if item.is_a? Rexle::Element then
408
+
410
409
  @child_lookup << [item.name, item.attributes, item.value]
411
410
  @child_elements << item
412
411
  # add a reference from this element (the parent) to the child
@@ -743,7 +742,18 @@ class Rexle
743
742
  def add_attribute(x) @doc.attribute(x) end
744
743
  def attribute(key) @doc.attribute(key) end
745
744
  def attributes() @doc.attributes end
746
- def add_element(element) @doc.root.add_element(element) end
745
+
746
+ def add_element(element)
747
+ if @doc then
748
+ raise 'attempted adding second root element to document' if @doc.root
749
+ @doc.root.add_element(element)
750
+ else
751
+ doc_node = ['doc','',{},[element.name, element.value,element.attributes]]
752
+ @doc = scan_element(*doc_node)
753
+ end
754
+ element
755
+ end
756
+
747
757
  def add_text(s) end
748
758
 
749
759
  alias add add_element
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rexle
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.64
5
+ version: 0.9.65
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-11-06 00:00:00 Z
13
+ date: 2012-11-10 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rexleparser