xml-smart 0.4.1 → 0.4.2

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
  SHA256:
3
- metadata.gz: 2c272b4aa72d95425ca2b859c94043b0bde69a567b5f10cccebd7dfcba68043e
4
- data.tar.gz: 2f5f5741e4e27ea007067f358b1b7136b7a2c78a96006297443a9358e5150dce
3
+ metadata.gz: bfea354650019ab5f80ac4522562ba55fb0e71b88885a74ada76b3f948c936b8
4
+ data.tar.gz: bcccdac2fb2eb4492af1301092fcbbb89f7458dea67854d857696586c3042eb7
5
5
  SHA512:
6
- metadata.gz: 36f069c18fe7280180ed36822acb2c21bdfb84f3de55bb01197188ba9fe975f283def0ff03a5dbfb3d378ea5f7cccd0633984ad86b27602a289099f0be72d94e
7
- data.tar.gz: 5b328fbc369182401edba0d3e0d24fe7f6a41252c444fd091dc73e2e9bf587e2472afd0901427b69981395e594447d6ed95e858bd797e78ef4ec974ead87c20e
6
+ metadata.gz: 4cf2e0c62c1f8be0d82a326c2c396e6849ce6670335296cb693168c11c4e8d4f1c239de944af2ab9d560b2d8720c2f7677951d8eb772eb10401d22a5096a60c9
7
+ data.tar.gz: 452a5dddb8f0235cb3a1d0839b9a72e060165177557fd439736f43d804a1918fa881e4b62c84627c0fd4c429bb626f6bdf3f4cb0db6fab1c5071d6a13caf4f1c
File without changes
@@ -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.rb 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 = []
@@ -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
@@ -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,67 @@ 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).dup)
176
+ when NodeSet; NodeSet.new @node.replace(n.instance_variable_get(:@nodeset).dup)
177
177
  else
178
178
  nil
179
179
  end
180
180
  end
181
181
 
182
- def qname; QName.new @element; end
183
- def attributes; AttributeSet.new @element; end
182
+ def qname; QName.new @node; end
183
+ def attributes; AttributeSet.new @node; end
184
184
 
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
185
+ def text; @node.xpath_fast("string(text())"); end
186
+ def text=(t); @node.content = t.to_s if t.respond_to? :to_s; end
187
187
 
188
188
  def children; find('*|text()'); end
189
189
  def children?; find('*|text()').length > 0 end
190
190
  def parent
191
- Dom::smart_helper(@element.parent)
191
+ Dom::smart_helper(@node.parent)
192
192
  end
193
- def parent?; !@element.parent.nil?; end
193
+ def parent?; !@node.parent.nil?; end
194
194
 
195
195
  def empty?; !children?; end
196
196
  def mixed?;
197
- @element.xpath_fast('*').length > 0 && @element.xpath_fast("string(text())") != '';
197
+ @node.xpath_fast('*').length > 0 && @node.xpath_fast("string(text())") != '';
198
198
  end
199
199
  def text_only?;
200
- @element.xpath_fast('*').length == 0 && @element.xpath_fast("string(text())") != '';
200
+ @node.xpath_fast('*').length == 0 && @node.xpath_fast("string(text())") != '';
201
201
  end
202
202
  def element_only?;
203
- @element.xpath_fast('*').length > 0 && @element.xpath_fast("string(text())") == '';
203
+ @node.xpath_fast('*').length > 0 && @node.xpath_fast("string(text())") == '';
204
204
  end
205
205
 
206
- def path; @element.path[-1] != ']' ? @element.path + '[1]' : @element.path; end
206
+ def path; @node.path[-1] != ']' ? @node.path + '[1]' : @node.path; end
207
207
 
208
208
  def ==(other)
209
209
  return false unless other
210
210
  return false unless other.respond_to?(:unique_id)
211
211
  unique_id == other.unique_id
212
212
  end
213
- def unique_id; @element.pointer_id; end
213
+ def unique_id; @node.pointer_id; end
214
214
 
215
215
  def to_doc
216
216
  doc = Nokogiri::XML::Document.new
217
- doc.root = @element
217
+ doc.root = @node
218
218
  Dom.new(doc)
219
219
  end
220
220
  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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "xml-smart"
3
- s.version = "0.4.1"
3
+ s.version = "0.4.2"
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.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: example
10
10
  cert_chain: []
11
- date: 2020-03-18 00:00:00.000000000 Z
11
+ date: 2020-06-05 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,10 +83,9 @@ files:
82
83
  - COPYING
83
84
  - README.rdoc
84
85
  - Rakefile
86
+ - example/CARD.xml
85
87
  - example/EXAMPLE.xml
86
- - example/SIC.ml
87
- - example/ssss.xml
88
- - example/xpath_visual.rb
88
+ - example/xpath_visual
89
89
  - lib/xml/XSDtoRNG.xsl
90
90
  - lib/xml/smart.rb
91
91
  - lib/xml/smart_dom.rb
@@ -1,10 +0,0 @@
1
- <Customers>
2
- <Customer ID="1">
3
- Queen Falafel
4
- <Address>Stollgasse</Address>
5
- </Customer>
6
- <Customer ID="2">
7
- Queen Falafel
8
- <Address>Wagramerstrasse</Address>
9
- </Customer>
10
- </Customers>