xml-smart 0.4.0 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebd201f9be7bb0199d0469f607171f112c33e1d08214f0cc5f4c37824bb2bd83
4
- data.tar.gz: 2e65919e93b6d6d4e4bce9ac5db39d2f531500cd8c068dc1177cf2098e3debb2
3
+ metadata.gz: '0082580453384e4fc3faf5b355f6aa8ce68d77e620fc520b4712659190e900b1'
4
+ data.tar.gz: 6e690294fe78c3d3a28f7be10a147f498ec0775a324ae63c02e786ed35972e55
5
5
  SHA512:
6
- metadata.gz: ffa85c13c8413d7740fb825d4239ccfd5df0b42df6cd15a6b5e46530d51723dc5ee330de4506323c53e1c582d933d75ffa668c123ef463c977796b0151c60a1b
7
- data.tar.gz: ba0b3f7b32e8c986abd621f736e1fa22a77a8d76b09529c8e359b688b543926657caf2c77479d6b88009c4a0c0a159d04975c87cde259b5abae658f5bafaa761
6
+ metadata.gz: a009c08c31957a69772a05764ab7334ce878d6d009f779c248715fb4cd40595f034b4cba04d03fb656d20cb31ceaa690e65f265d98a7cba54f7af625b78b1ba2
7
+ data.tar.gz: 94475b9125ff888bf800e6e466b99892833de16d99f0b5417f995853454c66e7987f5070f5650983f02f468a3154a20b90a35f7e578b80dda42827a33cb10b9e
data/example/CARD.xml ADDED
@@ -0,0 +1,64 @@
1
+ <?xml version="1.0"?>
2
+ <hipster_kitchen>
3
+ <dish_of_the_day day="Mo" type="meat">
4
+ <name>QUICHE LORRAINE</name>
5
+ <alergens>
6
+ <alergen>a</alergen>
7
+ <alergen>c</alergen>
8
+ <alergen>g</alergen>
9
+ <alergen>l</alergen>
10
+ </alergens>
11
+ </dish_of_the_day>
12
+ <dish_of_the_day day="Di" type="vegetarian">
13
+ <name>MAROKKANISCHER COUSCOUS</name>
14
+ <alergens>
15
+ <alergen>a</alergen>
16
+ <alergen>gl</alergen>
17
+ </alergens>
18
+ </dish_of_the_day>
19
+ <dish_of_the_day day="Mi" type="meat">
20
+ <name>ASIATISCHE H&#xDC;HNERSPIESSE</name>
21
+ <alergens>
22
+ <alergen>gl</alergen>
23
+ <alergen>lf</alergen>
24
+ <alergen>f</alergen>
25
+ <alergen>m</alergen>
26
+ <alergen>o</alergen>
27
+ </alergens>
28
+ </dish_of_the_day>
29
+ <dish_of_the_day day="Fr" type="vegetarian">
30
+ <name>ITALIENISCHES ANTIPASTIPI</name>
31
+ <alergens>
32
+ <alergen maybe="true">a</alergen>
33
+ <alergen>g</alergen>
34
+ <alergen>h</alergen>
35
+ <alergen>l</alergen>
36
+ </alergens>
37
+ </dish_of_the_day>
38
+ <dish_of_the_day type="vegan">
39
+ <name>SOMMER-CURRY</name>
40
+ <alergens>
41
+ <alergen>gl</alergen>
42
+ <alergen>lf</alergen>
43
+ <alergen>l</alergen>
44
+ </alergens>
45
+ </dish_of_the_day>
46
+ <alergenes>
47
+ <alergene id="gl">glutenfrei</alergene>
48
+ <alergene id="lf">lactosefrei</alergene>
49
+ <alergene id="a">glutenhaltiges getreide</alergene>
50
+ <alergene id="b">krebstiere &amp; daraus gewonnene erzeugnisse</alergene>
51
+ <alergene id="c">ei von gefl&#xFC;gel &amp; daraus gewonnene erzeugnisse</alergene>
52
+ <alergene id="d">fisch &amp; daraus gewonnene erzeugnisse</alergene>
53
+ <alergene id="e">erdnuss &amp; daraus gewonnene erzeugnisse</alergene>
54
+ <alergene id="f">soja &amp; daraus gewonnene erzeugnisse</alergene>
55
+ <alergene id="g">milch von s&#xE4;ugetieren wie kuh, schaf, ziege, pferd &amp; esel &amp; daraus gewonnene erzeugnisse</alergene>
56
+ <alergene id="h">schalenfr&#xFC;chte</alergene>
57
+ <alergene id="l">sellerie</alergene>
58
+ <alergene id="m">senf &amp; daraus gewonnene erzeugnisse</alergene>
59
+ <alergene id="n">sesam &amp; daraus gewonnene erzeugnisse</alergene>
60
+ <alergene id="o">sulfit</alergene>
61
+ <alergene id="p">lupinen &amp; daraus gewonnene erzeugnisse</alergene>
62
+ <alergene id="r">weichtiere wie z.b.: muscheln, austern, schnecken &amp; daraus gewonnene erzeugnisse</alergene>
63
+ </alergenes>
64
+ </hipster_kitchen>
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby
2
2
  require 'rubygems'
3
3
  require 'term/ansicolor'
4
- require "#{File.dirname($0)}/../lib/xml/smart"
4
+ require_relative "../lib/xml/smart"
5
5
  include Term::ANSIColor
6
6
 
7
7
  def rememberPath(path,output)
@@ -30,10 +30,21 @@ def prnTree(node,depth,mixed)
30
30
  print "\n" unless mixed
31
31
  end
32
32
 
33
- doc = XML::Smart.open(File.dirname($0) + "/EXAMPLE.xml")
33
+ def help
34
+ puts "Usage: xpath_visual FILE \"XPATH\""
35
+ exit
36
+ end
34
37
 
35
- # xpath expression that should be visualised
36
- xpath = ARGV[0] || "/"
38
+ if ARGV.length < 2
39
+ help
40
+ else
41
+ # xpath expression that should be visualised
42
+ xpath = ARGV[1..-1].join(' ') || "/"
43
+ unless File.exists?(ARGV[0])
44
+ help
45
+ end
46
+ doc = XML::Smart.open_unprotected(ARGV[0])
47
+ end
37
48
 
38
49
  # remember pathes, that an xpath expression selects
39
50
  @remember = []
data/lib/xml/smart.rb CHANGED
@@ -103,7 +103,7 @@ module Nokogiri
103
103
  ctx.evaluate('.//xi:include').each do |ele|
104
104
  name = ele.attributes['href'].value
105
105
  name = path + name if name !~ /^(https?:|ftp:|\/)/
106
- content = open(name,{ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).read
106
+ content = open(name,:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read
107
107
  insert = begin
108
108
  Nokogiri::XML::parse(content).root # {|config| config.noblanks.noent.strict }.root
109
109
  rescue
@@ -164,14 +164,14 @@ module XML
164
164
  begin
165
165
  if name.is_a?(String) && File.exist?(name)
166
166
  MUTEX.synchronize do
167
- io = ::Kernel::open(name,'r+')
167
+ io = ::URI::open(name,'r+')
168
168
  io.flock(File::LOCK_EX)
169
169
  end
170
170
  dom = Dom.new Nokogiri::XML::parse(io){|config| config.noblanks.noent.nsclean.strict }, name
171
171
  io.rewind
172
172
  elsif name.is_a?(String) && !File.exist?(name)
173
173
  MUTEX.synchronize do
174
- io = ::Kernel::open(name,'w')
174
+ io = ::URI::open(name,'w')
175
175
  io.flock(File::LOCK_EX)
176
176
  end
177
177
  dom = Smart::string(default,name)
@@ -217,7 +217,7 @@ module XML
217
217
  filename = nil
218
218
  io = if name.is_a?(String)
219
219
  filename = name
220
- ::Kernel::open(name)
220
+ ::URI::open(name)
221
221
  else
222
222
  filename = name.path
223
223
  name
@@ -257,4 +257,9 @@ module XML
257
257
 
258
258
  class Error < RuntimeError; end
259
259
  end
260
+
261
+ module Common
262
+ def self::pretty_path
263
+ end
264
+ end
260
265
  end
data/lib/xml/smart_dom.rb CHANGED
@@ -13,7 +13,7 @@ module XML
13
13
  Element.new(@dom.root)
14
14
  end
15
15
  def root=(nr)
16
- @dom.root.replace(nr.instance_variable_get(:@element)) if nr.instance_of? Element
16
+ @dom.root.replace(nr.instance_variable_get(:@node)) if nr.instance_of? Element
17
17
  end
18
18
 
19
19
  def find(path)
@@ -49,7 +49,7 @@ module XML
49
49
  def save_as(name)
50
50
  raise Error, 'first parameter has to be a filename or filehandle' unless name.is_a?(String) || name.is_a?(IO) || name.is_a?(Tempfile)
51
51
  begin
52
- io = name.is_a?(String) ? ::Kernel::open(name,'w') : name
52
+ io = name.is_a?(String) ? ::URI::open(name,'w') : name
53
53
  rescue
54
54
  raise Error, "could not open #{name}"
55
55
  end
@@ -70,20 +70,20 @@ module XML
70
70
 
71
71
  def xinclude!(basedir=nil)
72
72
  Element.new(@dom.root).xinclude!(basedir)
73
- end
73
+ end
74
74
 
75
75
  def self::smart_helper(node)
76
76
  if node.instance_of? Nokogiri::XML::Element
77
77
  XML::Smart::Dom::Element.new(node)
78
78
  elsif node.instance_of? Nokogiri::XML::Attr
79
79
  XML::Smart::Dom::Attribute.new(node)
80
- elsif node.instance_of? Nokogiri::XML::NodeSet
80
+ elsif node.instance_of? Nokogiri::XML::NodeSet
81
81
  XML::Smart::Dom::NodeSet.new(node)
82
- elsif node.instance_of?(String) || node.instance_of?(TrueClass) || node.instance_of?(FalseClass) || node.instance_of?(Float)
82
+ elsif node.instance_of?(String) || node.instance_of?(TrueClass) || node.instance_of?(FalseClass) || node.instance_of?(Float)
83
83
  node
84
- elsif node.instance_of? Nokogiri::XML::Text
84
+ elsif node.instance_of? Nokogiri::XML::Text
85
85
  XML::Smart::Dom::Text.new(node)
86
- elsif node.instance_of? Nokogiri::XML::Namespace
86
+ elsif node.instance_of? Nokogiri::XML::Namespace
87
87
  XML::Smart::Dom::Namespace.new(node)
88
88
  elsif node.instance_of? Nokogiri::XML::Document
89
89
  XML::Smart::Dom.new(node)
@@ -93,7 +93,7 @@ module XML
93
93
  nil
94
94
  else
95
95
  XML::Smart::Dom::Other.new(node)
96
- end
96
+ end
97
97
  end
98
98
 
99
99
  def validate_against(doc,&errbl)
@@ -114,9 +114,9 @@ module XML
114
114
  res = Nokogiri::XSLT::Stylesheet.parse_stylesheet_doc(doc.instance_variable_get(:@dom)).transform(@dom,params)
115
115
  if res.children.length != 0 && res.children.first.class == Nokogiri::XML::Text
116
116
  Text.new(res.children.first).text
117
- else
117
+ else
118
118
  Dom::smart_helper(res)
119
- end
119
+ end
120
120
  end
121
121
 
122
122
  end
@@ -4,31 +4,34 @@ module XML
4
4
 
5
5
  class Attribute
6
6
  def initialize(attr)
7
- @attr = attr
7
+ @node = attr
8
8
  end
9
9
 
10
10
  def ===(cls); self.is_a? cls; end
11
11
 
12
- def to_s; @attr.content; end
13
- def to_i; @attr.content.to_i; end
14
- def to_f; @attr.content.to_f; end
12
+ def to_s; @node.content; end
13
+ def to_i; @node.content.to_i; end
14
+ def to_f; @node.content.to_f; end
15
15
 
16
- def qname; QName.new @attr; end
17
- def path; @attr.path; end
16
+ def qname; QName.new @node; end
17
+ def path; @node.path; end
18
18
 
19
- def value; @attr.content; end;
20
- def value=(val); @attr.content = val; end;
19
+ def value; @node.content; end;
20
+ def value=(val); @node.content = val; end;
21
21
 
22
22
  def ==(other)
23
23
  return false unless other
24
24
  return false unless other.respond_to?(:unique_id)
25
25
  unique_id == other.unique_id
26
26
  end
27
- def unique_id; @attr.pointer_id; end
27
+ def unique_id; @node.pointer_id; end
28
28
 
29
- def parent; Dom::smart_helper(@attr.parent); end
29
+ def parent; Dom::smart_helper(@node.parent); end
30
+
31
+ alias :text :value
32
+ alias :text= :value=
30
33
  end
31
34
 
32
- end
33
- end
34
- end
35
+ end
36
+ end
37
+ end
@@ -4,13 +4,13 @@ module XML
4
4
 
5
5
  class Element
6
6
  def initialize(element)
7
- @element = element
7
+ @node = element
8
8
  end
9
9
 
10
10
  def ===(cls); self.is_a? cls; end
11
11
 
12
12
  def find(xpath)
13
- Dom::smart_helper(@element.xpath_fast(xpath))
13
+ Dom::smart_helper(@node.xpath_fast(xpath))
14
14
  end
15
15
 
16
16
  def add_helper(attrs)
@@ -20,24 +20,24 @@ module XML
20
20
  attrs[0] = attrs[0].dup
21
21
  if attrs[0].sub!(/([^:]+):/, '')
22
22
  pfx = $1
23
- if @element.document.user_custom_namespace_prefixes.has_key?(pfx)
24
- @element.document.custom_namespace_prefixes.each do |k,v|
25
- if @element.document.user_custom_namespace_prefixes[pfx] == v
26
- ns = @element.document.user_custom_namespace_prefixes[pfx]
23
+ if @node.document.user_custom_namespace_prefixes.has_key?(pfx)
24
+ @node.document.custom_namespace_prefixes.each do |k,v|
25
+ if @node.document.user_custom_namespace_prefixes[pfx] == v
26
+ ns = @node.document.user_custom_namespace_prefixes[pfx]
27
27
  end
28
28
  end
29
29
  end
30
30
  if ns.nil?
31
- if @element.document.custom_namespace_prefixes.has_key?(pfx)
32
- ns = @element.document.custom_namespace_prefixes[pfx]
31
+ if @node.document.custom_namespace_prefixes.has_key?(pfx)
32
+ ns = @node.document.custom_namespace_prefixes[pfx]
33
33
  else
34
34
  raise Error, 'No valid namespace'
35
35
  end
36
36
  end
37
37
  end
38
- tmp = Nokogiri::XML::Node.new attrs[0], @element.document
38
+ tmp = Nokogiri::XML::Node.new attrs[0], @node.document
39
39
  unless ns.nil?
40
- @element.namespace_scopes.each do |nss|
40
+ @node.namespace_scopes.each do |nss|
41
41
  tmp.namespace = nss if nss.href == ns
42
42
  end
43
43
  end
@@ -59,13 +59,13 @@ module XML
59
59
  end
60
60
  return [tmp,false]
61
61
  elsif attrs.length == 1 && attrs[0].is_a?(XML::Smart::Dom::Element)
62
- ele = attrs[0].instance_variable_get(:@element)
63
- same = ele.document.root.pointer_id == @element.document.root.pointer_id
62
+ ele = attrs[0].instance_variable_get(:@node)
63
+ same = ele.document.root.pointer_id == @node.document.root.pointer_id
64
64
  return [same ? ele : ele.dup, !same]
65
65
  elsif attrs.length == 1 && attrs[0].is_a?(XML::Smart::Dom::NodeSet)
66
66
  nos = attrs[0].instance_variable_get(:@nodeset)
67
67
  if nos.length > 0
68
- same = nos.first.document.root.pointer_id == @element.document.root.pointer_id
68
+ same = nos.first.document.root.pointer_id == @node.document.root.pointer_id
69
69
  if same
70
70
  return [nos, false]
71
71
  else
@@ -76,13 +76,13 @@ module XML
76
76
  return [nos, false]
77
77
  end
78
78
  elsif attrs.length == 2 && attrs[0].is_a?(XML::Smart::Dom::Element) && (attrs[1] == XML::Smart::COPY || attrs[1] == XML::Smart::MOVE)
79
- ele = attrs[0].instance_variable_get(:@element)
80
- same = ele.document.root.pointer_id == @element.document.root.pointer_id
79
+ ele = attrs[0].instance_variable_get(:@node)
80
+ same = ele.document.root.pointer_id == @node.document.root.pointer_id
81
81
  return [attrs[1] == XML::Smart::COPY ? ele.dup : ele, !same]
82
82
  elsif attrs.length == 2 && attrs[0].is_a?(XML::Smart::Dom::NodeSet) && (attrs[1] == XML::Smart::COPY || attrs[1] == XML::Smart::MOVE)
83
83
  nos = attrs[0].instance_variable_get(:@nodeset)
84
84
  if nos.length > 0
85
- same = nos.first.document.root.pointer_id == @element.document.root.pointer_id
85
+ same = nos.first.document.root.pointer_id == @node.document.root.pointer_id
86
86
  if attrs[1] == XML::Smart::COPY
87
87
  tnos = nos.map{|e|e.dup}
88
88
  nos = Nokogiri::XML::NodeSet.new(nos.first.document,tnos)
@@ -92,7 +92,7 @@ module XML
92
92
  return [nos, false]
93
93
  end
94
94
  elsif attrs.length == 2 && attrs[0].is_a?(String) && attrs[1].is_a?(String) && attrs[0][0] == '?'
95
- tmp = Nokogiri::XML::ProcessingInstruction.new @element.document, attrs[0].sub(/./,''), attrs[1]
95
+ tmp = Nokogiri::XML::ProcessingInstruction.new @node.document, attrs[0].sub(/./,''), attrs[1]
96
96
  return [tmp,false]
97
97
  end
98
98
  return [nil, false]
@@ -100,10 +100,10 @@ module XML
100
100
  private :add_helper
101
101
  def add(*attrs)
102
102
  tmp, update = add_helper(attrs)
103
- res = Dom::smart_helper(@element.add_child tmp)
103
+ res = Dom::smart_helper(@node.add_child tmp)
104
104
  if update
105
- @element.document.custom_namespace_prefixes_update
106
- @element.document.ns_update
105
+ @node.document.custom_namespace_prefixes_update
106
+ @node.document.ns_update
107
107
  end
108
108
  res
109
109
  end
@@ -116,35 +116,35 @@ module XML
116
116
  end
117
117
  def add_before(*attrs)
118
118
  tmp, update = add_helper(attrs)
119
- res = Dom::smart_helper(@element.add_previous_sibling tmp)
119
+ res = Dom::smart_helper(@node.add_previous_sibling tmp)
120
120
  if update
121
- @element.document.custom_namespace_prefixes_update
122
- @element.document.ns_update
121
+ @node.document.custom_namespace_prefixes_update
122
+ @node.document.ns_update
123
123
  end
124
124
  res
125
125
  end
126
126
  def add_after(*attrs)
127
127
  tmp, update = add_helper(attrs)
128
- res = Dom::smart_helper(@element.add_next_sibling tmp)
128
+ res = Dom::smart_helper(@node.add_next_sibling tmp)
129
129
  if update
130
- @element.document.custom_namespace_prefixes_update
131
- @element.document.ns_update
130
+ @node.document.custom_namespace_prefixes_update
131
+ @node.document.ns_update
132
132
  end
133
133
  res
134
134
  end
135
135
 
136
136
  def dump
137
137
  doc = Nokogiri::XML::Document.new
138
- doc.root = @element
138
+ doc.root = @node
139
139
  doc.root.to_s
140
140
  end
141
141
 
142
- def to_s; @element.content; end
143
- def to_i; @element.content.to_i; end
144
- def to_f; @element.content.to_f; end
142
+ def to_s; @node.content; end
143
+ def to_i; @node.content.to_i; end
144
+ def to_f; @node.content.to_f; end
145
145
 
146
- def namespace?; !@element.namespace.nil?; end
147
- def namespace; namespace? ? Namespace.new(@element.namespace) : nil; end
146
+ def namespace?; !@node.namespace.nil?; end
147
+ def namespace; namespace? ? Namespace.new(@node.namespace) : nil; end
148
148
  def namespace=(n)
149
149
  n = case n
150
150
  when Namespace
@@ -154,67 +154,75 @@ module XML
154
154
  else
155
155
  return
156
156
  end
157
- tmp = @element.document.custom_namespace_prefixes[n] || @element.document.user_custom_namespace_prefixes[n]
157
+ tmp = @node.document.custom_namespace_prefixes[n] || @node.document.user_custom_namespace_prefixes[n]
158
158
  unless tmp.nil?
159
- @element.namespace_scopes.each do |nss|
160
- @element.namespace = nss if nss.href == tmp
159
+ @node.namespace_scopes.each do |nss|
160
+ @node.namespace = nss if nss.href == tmp
161
161
  end
162
162
  end
163
163
  end
164
- def namespaces; NamespaceSet.new(self,@element); end
164
+ def namespaces; NamespaceSet.new(self,@node); end
165
165
 
166
166
  def xinclude!(basedir=nil)
167
- @element.do_xinclude_manual(basedir)
168
- @element.document.custom_namespace_prefixes_update
169
- @element.document.ns_update
167
+ @node.do_xinclude_manual(basedir)
168
+ @node.document.custom_namespace_prefixes_update
169
+ @node.document.ns_update
170
170
  true
171
171
  end
172
172
 
173
173
  def replace_by(n)
174
174
  case n
175
- when Element; Element.new @element.replace(n.instance_variable_get(:@element).dup)
176
- when NodeSet; NodeSet.new @element.replace(n.instance_variable_get(:@nodeset).dup)
175
+ when Element; Element.new @node.replace(n.instance_variable_get(:@node))
176
+ when NodeSet; NodeSet.new @node.replace(n.instance_variable_get(:@nodeset))
177
+ else
178
+ nil
179
+ end
180
+ end
181
+ def replace_by_copy(n)
182
+ case n
183
+ when Element; Element.new @node.replace(n.instance_variable_get(:@node).dup)
184
+ when NodeSet; NodeSet.new @node.replace(n.instance_variable_get(:@nodeset).dup)
177
185
  else
178
186
  nil
179
187
  end
180
188
  end
181
189
 
182
- def qname; QName.new @element; end
183
- def attributes; AttributeSet.new @element; end
190
+ def qname; QName.new @node; end
191
+ def attributes; AttributeSet.new @node; end
184
192
 
185
- def text; @element.xpath_fast("string(text())"); end
186
- def text=(t); @element.content = t.to_s if t.respond_to? :to_s; end
193
+ def text; @node.xpath_fast("string(text())"); end
194
+ def text=(t); @node.content = t.to_s if t.respond_to? :to_s; end
187
195
 
188
196
  def children; find('*|text()'); end
189
197
  def children?; find('*|text()').length > 0 end
190
198
  def parent
191
- Dom::smart_helper(@element.parent)
199
+ Dom::smart_helper(@node.parent)
192
200
  end
193
- def parent?; !@element.parent.nil?; end
201
+ def parent?; !@node.parent.nil?; end
194
202
 
195
203
  def empty?; !children?; end
196
204
  def mixed?;
197
- @element.xpath_fast('*').length > 0 && @element.xpath_fast("string(text())") != '';
205
+ @node.xpath_fast('*').length > 0 && @node.xpath_fast("string(text())") != '';
198
206
  end
199
207
  def text_only?;
200
- @element.xpath_fast('*').length == 0 && @element.xpath_fast("string(text())") != '';
208
+ @node.xpath_fast('*').length == 0 && @node.xpath_fast("string(text())") != '';
201
209
  end
202
210
  def element_only?;
203
- @element.xpath_fast('*').length > 0 && @element.xpath_fast("string(text())") == '';
211
+ @node.xpath_fast('*').length > 0 && @node.xpath_fast("string(text())") == '';
204
212
  end
205
213
 
206
- def path; @element.path[-1] != ']' ? @element.path + '[1]' : @element.path; end
214
+ def path; @node.path[-1] != ']' ? @node.path + '[1]' : @node.path; end
207
215
 
208
216
  def ==(other)
209
217
  return false unless other
210
218
  return false unless other.respond_to?(:unique_id)
211
219
  unique_id == other.unique_id
212
220
  end
213
- def unique_id; @element.pointer_id; end
221
+ def unique_id; @node.pointer_id; end
214
222
 
215
223
  def to_doc
216
224
  doc = Nokogiri::XML::Document.new
217
- doc.root = @element
225
+ doc.root = @node
218
226
  Dom.new(doc)
219
227
  end
220
228
  end
@@ -45,7 +45,7 @@ module XML
45
45
  nnew.add(nold.children)
46
46
  nold.replace_by(nnew)
47
47
  @node = nnod
48
- @parent.instance_variable_set(:@element,@node)
48
+ @parent.instance_variable_set(:@node,@node)
49
49
  @node.document.custom_namespace_prefixes_update
50
50
  @node.document.ns_update
51
51
  Namespace.new(ns)
@@ -64,7 +64,7 @@ module XML
64
64
  nnew.add(nold.children)
65
65
  nold.replace_by(nnew)
66
66
  @node = nnod
67
- @parent.instance_variable_set(:@element,@node)
67
+ @parent.instance_variable_set(:@node,@node)
68
68
  @node.document.custom_namespace_prefixes_update
69
69
  @node.document.ns_update
70
70
  nil
@@ -92,7 +92,7 @@ module XML
92
92
  nnew.add(nold.children)
93
93
  nold.replace_by(nnew)
94
94
  @node = nnod
95
- @parent.instance_variable_set(:@element,@node)
95
+ @parent.instance_variable_set(:@node,@node)
96
96
  @node.document.custom_namespace_prefixes_update
97
97
  @node.document.ns_update
98
98
  true
@@ -115,7 +115,7 @@ module XML
115
115
  nnew.add(nold.children)
116
116
  nold.replace_by(nnew)
117
117
  @node = nnod
118
- @parent.instance_variable_set(:@element,@node)
118
+ @parent.instance_variable_set(:@node,@node)
119
119
  @node.document.custom_namespace_prefixes_update
120
120
  @node.document.ns_update
121
121
  self
@@ -4,13 +4,13 @@ module XML
4
4
 
5
5
  class Other < Text
6
6
  def otype
7
- case @text
7
+ case @node
8
8
  when Nokogiri::XML::Comment; :comment
9
9
  else; :unknown
10
10
  end
11
11
  end
12
12
  end
13
-
13
+
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -3,23 +3,23 @@ module XML
3
3
  class Dom
4
4
 
5
5
  class Text
6
- def initialize(text); @text = text; end
6
+ def initialize(text); @node = text; end
7
7
 
8
8
  def ===(cls); self.is_a? cls; end
9
9
 
10
10
  def dump; to_s; end
11
- def to_s; @text.content.to_s; end
12
- def to_f; @text.content.to_f; end
13
- def to_i; @text.content.to_i; end
11
+ def to_s; @node.content.to_s; end
12
+ def to_f; @node.content.to_f; end
13
+ def to_i; @node.content.to_i; end
14
14
 
15
- def text; @text.content; end
16
- def text=(t); @text.content = t.to_s if t.respond_to? :to_s; end
15
+ def text; @node.content; end
16
+ def text=(t); @node.content = t.to_s if t.respond_to? :to_s; end
17
17
 
18
- def parent; Node.new(@text.parent); end
18
+ def parent; Node.new(@node.parent); end
19
19
 
20
- def path; @text.path; end
20
+ def path; @node.path; end
21
21
  end
22
-
22
+
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -3,39 +3,39 @@ module XML
3
3
 
4
4
  class ProcessingInstruction
5
5
  def initialize(element)
6
- @element = element
6
+ @node = element
7
7
  end
8
8
 
9
9
  def ===(cls); self.is_a? cls; end
10
10
 
11
- def dump; @element.to_s; end
11
+ def dump; @node.to_s; end
12
12
 
13
13
  def replace_by(n)
14
14
  case n
15
- when ProcessingInstruction; ProcessingInstruction.new @element.replace(n.instance_variable_get(:@element))
15
+ when ProcessingInstruction; ProcessingInstruction.new @node.replace(n.instance_variable_get(:@node))
16
16
  else
17
17
  nil
18
18
  end
19
19
  end
20
20
 
21
- def qname; QName.new @element; end
21
+ def qname; QName.new @node; end
22
22
 
23
- def content; @element.content end
24
- def content=(t); @element.content = t.to_s if t.respond_to? :to_s; end
23
+ def content; @node.content end
24
+ def content=(t); @node.content = t.to_s if t.respond_to? :to_s; end
25
25
 
26
26
  def parent
27
- Dom::smart_helper(@element.parent)
27
+ Dom::smart_helper(@node.parent)
28
28
  end
29
- def parent?; !@element.parent.nil?; end
29
+ def parent?; !@node.parent.nil?; end
30
30
 
31
- def path; @element.path; end
31
+ def path; @node.path; end
32
32
 
33
33
  def ==(other)
34
34
  return false unless other
35
35
  return false unless other.respond_to?(:unique_id)
36
36
  unique_id == other.unique_id
37
37
  end
38
- def unique_id; @element.pointer_id; end
38
+ def unique_id; @node.pointer_id; end
39
39
  end
40
40
  end
41
41
  end
data/test/EXAMPLE.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <test xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xml:lang="de">
2
2
  <names>
3
- <name team="0" a="3">2017-12-01 11:51:05 +0100</name>
3
+ <name team="0" a="3">2020-06-05 23:34:48 +0200</name>
4
4
  <name team="1">Jürgen</name>
5
5
  <name team="1">Michel</name>
6
6
  <name team="1">Raphi</name>
@@ -12,7 +12,7 @@ class TestNamespaceDefault < Minitest::Test
12
12
  assert(doc.namespaces.length == 2)
13
13
  assert(doc.namespaces.key? 'soap')
14
14
  assert(doc.namespaces.key? 'x')
15
-
15
+
16
16
  # add an element hallo to root
17
17
  nsnode = doc.root.add("hallo")
18
18
 
@@ -50,7 +50,7 @@ class TestNamespaceDefault < Minitest::Test
50
50
  nsnode.namespaces.add("aaa","http://heise2")
51
51
 
52
52
  assert(nsnode.namespaces[nil] == nil)
53
-
53
+
54
54
  nsnode.namespaces.add(nil,"http://heise")
55
55
  nsnode.namespaces[nil] = "http://heiser"
56
56
 
@@ -61,13 +61,13 @@ class TestNamespaceDefault < Minitest::Test
61
61
  assert(nsnode.namespaces['xmlns'].href == "http://heiser")
62
62
  assert(nsnode.namespaces['aaa'].href == "http://heise2")
63
63
  assert(nsnode.namespaces['test'].href == "http://heise1")
64
-
64
+
65
65
  assert(doc.namespaces.length == 5)
66
66
  nsnode.namespaces.delete_at('aaa')
67
67
  assert(nsnode.namespaces['aaa'].nil?)
68
-
68
+
69
69
  assert(doc.namespaces.length == 4)
70
70
  nsnode.namespaces.delete_all!
71
71
  assert(doc.namespaces.length == 2)
72
- end
73
- end
72
+ end
73
+ end
data/xml-smart.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "xml-smart"
3
- s.version = "0.4.0"
3
+ s.version = "0.4.4"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0"
6
6
  s.summary = "An xml library that doesn't suck - since 2004."
@@ -11,6 +11,8 @@ Gem::Specification.new do |s|
11
11
  s.require_path = 'lib'
12
12
  s.extra_rdoc_files = ['README.rdoc']
13
13
  s.test_files = Dir['test/tc_*.rb','test/*.xml','test/*.rng','test/*.xsd','test/smartrunner.rb','minitest/*']
14
+ s.bindir = 'example'
15
+ s.executables = ['xpath_visual']
14
16
 
15
17
  s.authors = ['Juergen eTM Mangler']
16
18
  s.email = 'juergen.mangler@gmail.com'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml-smart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
- autorequire:
9
- bindir: bin
8
+ autorequire:
9
+ bindir: example
10
10
  cert_chain: []
11
- date: 2019-03-27 00:00:00.000000000 Z
11
+ date: 2021-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -73,7 +73,8 @@ dependencies:
73
73
  description: An xml library that doesn't suck (since 2004). Based on Nokogiri since
74
74
  2012. For more info check out the Documentation link below.
75
75
  email: juergen.mangler@gmail.com
76
- executables: []
76
+ executables:
77
+ - xpath_visual
77
78
  extensions: []
78
79
  extra_rdoc_files:
79
80
  - README.rdoc
@@ -82,8 +83,9 @@ files:
82
83
  - COPYING
83
84
  - README.rdoc
84
85
  - Rakefile
86
+ - example/CARD.xml
85
87
  - example/EXAMPLE.xml
86
- - example/xpath_visual.rb
88
+ - example/xpath_visual
87
89
  - lib/xml/XSDtoRNG.xsl
88
90
  - lib/xml/smart.rb
89
91
  - lib/xml/smart_dom.rb
@@ -147,7 +149,7 @@ homepage: http://www.wst.univie.ac.at/~mangler/xml-smart/
147
149
  licenses:
148
150
  - LGPL-3.0
149
151
  metadata: {}
150
- post_install_message:
152
+ post_install_message:
151
153
  rdoc_options: []
152
154
  require_paths:
153
155
  - lib
@@ -162,53 +164,52 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
164
  - !ruby/object:Gem::Version
163
165
  version: '0'
164
166
  requirements: []
165
- rubyforge_project:
166
- rubygems_version: 2.7.6
167
- signing_key:
167
+ rubygems_version: 3.2.22
168
+ signing_key:
168
169
  specification_version: 4
169
170
  summary: An xml library that doesn't suck - since 2004.
170
171
  test_files:
171
- - test/tc_qname.rb
172
+ - test/tc_add.rb
173
+ - test/tc_basic.rb
174
+ - test/tc_concurrent.rb
175
+ - test/tc_copy.rb
176
+ - test/tc_create.rb
172
177
  - test/tc_delete.rb
173
- - test/tc_root.rb
174
- - test/tc_xinclude.rb
175
- - test/tc_write.rb
178
+ - test/tc_move_elements.rb
179
+ - test/tc_namespace_default.rb
180
+ - test/tc_namespace_detailed.rb
176
181
  - test/tc_namespace_find.rb
177
- - test/tc_sort.rb
178
182
  - test/tc_nested.rb
179
- - test/tc_xmlschema.rb
180
- - test/tc_xpath_attrs.rb
181
- - test/tc_namespace_default.rb
182
- - test/tc_version.rb
183
+ - test/tc_pi.rb
184
+ - test/tc_qname.rb
185
+ - test/tc_relaxng.rb
186
+ - test/tc_root.rb
183
187
  - test/tc_set_or_replace.rb
188
+ - test/tc_sort.rb
184
189
  - test/tc_string.rb
185
- - test/tc_xsl.rb
186
- - test/tc_concurrent.rb
187
- - test/tc_xpath_root.rb
188
- - test/tc_namespace_detailed.rb
189
- - test/tc_copy.rb
190
- - test/tc_basic.rb
191
- - test/tc_move_elements.rb
192
- - test/tc_create.rb
190
+ - test/tc_todoc.rb
191
+ - test/tc_version.rb
192
+ - test/tc_write.rb
193
+ - test/tc_xinclude.rb
194
+ - test/tc_xmlschema.rb
193
195
  - test/tc_xpath.rb
194
- - test/tc_relaxng.rb
196
+ - test/tc_xpath_attrs.rb
195
197
  - test/tc_xpath_functions.rb
196
- - test/tc_pi.rb
197
- - test/tc_add.rb
198
- - test/tc_todoc.rb
199
- - test/HELLO.xml
200
- - test/EXAMPLE-NS.xml
201
- - test/3.xml
202
- - test/XSL_BASE.xml
198
+ - test/tc_xpath_root.rb
199
+ - test/tc_xsl.rb
203
200
  - test/1.xml
204
- - test/EXAMPLE.str.xml
205
201
  - test/2.xml
206
- - test/EXAMPLE.xml
202
+ - test/3.xml
203
+ - test/EXAMPLE-NS.xml
207
204
  - test/EXAMPLE-NSE.xml
208
- - test/concurrent.xml
205
+ - test/EXAMPLE.str.xml
206
+ - test/EXAMPLE.tmp.xml
207
+ - test/EXAMPLE.xml
209
208
  - test/HELLO-MORE.xml
209
+ - test/HELLO.xml
210
+ - test/XSL_BASE.xml
210
211
  - test/XSL_DOCUMENT.xml
211
- - test/EXAMPLE.tmp.xml
212
+ - test/concurrent.xml
212
213
  - test/HELLO.rng
213
214
  - test/HELLO.xsd
214
215
  - test/smartrunner.rb