xml-smart 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/{ssss.xml → CARD.xml} +0 -0
- data/example/{xpath_visual.rb → xpath_visual} +15 -4
- data/lib/xml/smart.rb +5 -0
- data/lib/xml/smart_domattribute.rb +16 -13
- data/lib/xml/smart_domelement.rb +53 -53
- data/lib/xml/smart_domtext.rb +10 -10
- data/lib/xml/smart_processinginstruction.rb +10 -10
- data/xml-smart.gemspec +3 -1
- metadata +7 -7
- data/example/SIC.ml +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfea354650019ab5f80ac4522562ba55fb0e71b88885a74ada76b3f948c936b8
|
4
|
+
data.tar.gz: bcccdac2fb2eb4492af1301092fcbbb89f7458dea67854d857696586c3042eb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
33
|
+
def help
|
34
|
+
puts "Usage: xpath_visual.rb FILE \"XPATH\""
|
35
|
+
exit
|
36
|
+
end
|
34
37
|
|
35
|
-
|
36
|
-
|
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
@@ -4,31 +4,34 @@ module XML
|
|
4
4
|
|
5
5
|
class Attribute
|
6
6
|
def initialize(attr)
|
7
|
-
@
|
7
|
+
@node = attr
|
8
8
|
end
|
9
9
|
|
10
10
|
def ===(cls); self.is_a? cls; end
|
11
11
|
|
12
|
-
def to_s; @
|
13
|
-
def to_i; @
|
14
|
-
def to_f; @
|
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 @
|
17
|
-
def path; @
|
16
|
+
def qname; QName.new @node; end
|
17
|
+
def path; @node.path; end
|
18
18
|
|
19
|
-
def value; @
|
20
|
-
def value=(val); @
|
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; @
|
27
|
+
def unique_id; @node.pointer_id; end
|
28
28
|
|
29
|
-
def parent; Dom::smart_helper(@
|
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
|
data/lib/xml/smart_domelement.rb
CHANGED
@@ -4,13 +4,13 @@ module XML
|
|
4
4
|
|
5
5
|
class Element
|
6
6
|
def initialize(element)
|
7
|
-
@
|
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(@
|
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 @
|
24
|
-
@
|
25
|
-
if @
|
26
|
-
ns = @
|
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 @
|
32
|
-
ns = @
|
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], @
|
38
|
+
tmp = Nokogiri::XML::Node.new attrs[0], @node.document
|
39
39
|
unless ns.nil?
|
40
|
-
@
|
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(:@
|
63
|
-
same = ele.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 == @
|
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(:@
|
80
|
-
same = ele.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 == @
|
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 @
|
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(@
|
103
|
+
res = Dom::smart_helper(@node.add_child tmp)
|
104
104
|
if update
|
105
|
-
@
|
106
|
-
@
|
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(@
|
119
|
+
res = Dom::smart_helper(@node.add_previous_sibling tmp)
|
120
120
|
if update
|
121
|
-
@
|
122
|
-
@
|
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(@
|
128
|
+
res = Dom::smart_helper(@node.add_next_sibling tmp)
|
129
129
|
if update
|
130
|
-
@
|
131
|
-
@
|
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 = @
|
138
|
+
doc.root = @node
|
139
139
|
doc.root.to_s
|
140
140
|
end
|
141
141
|
|
142
|
-
def to_s; @
|
143
|
-
def to_i; @
|
144
|
-
def to_f; @
|
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?; !@
|
147
|
-
def namespace; namespace? ? Namespace.new(@
|
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 = @
|
157
|
+
tmp = @node.document.custom_namespace_prefixes[n] || @node.document.user_custom_namespace_prefixes[n]
|
158
158
|
unless tmp.nil?
|
159
|
-
@
|
160
|
-
@
|
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,@
|
164
|
+
def namespaces; NamespaceSet.new(self,@node); end
|
165
165
|
|
166
166
|
def xinclude!(basedir=nil)
|
167
|
-
@
|
168
|
-
@
|
169
|
-
@
|
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 @
|
176
|
-
when NodeSet; NodeSet.new @
|
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 @
|
183
|
-
def attributes; AttributeSet.new @
|
182
|
+
def qname; QName.new @node; end
|
183
|
+
def attributes; AttributeSet.new @node; end
|
184
184
|
|
185
|
-
def text; @
|
186
|
-
def text=(t); @
|
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(@
|
191
|
+
Dom::smart_helper(@node.parent)
|
192
192
|
end
|
193
|
-
def parent?; !@
|
193
|
+
def parent?; !@node.parent.nil?; end
|
194
194
|
|
195
195
|
def empty?; !children?; end
|
196
196
|
def mixed?;
|
197
|
-
@
|
197
|
+
@node.xpath_fast('*').length > 0 && @node.xpath_fast("string(text())") != '';
|
198
198
|
end
|
199
199
|
def text_only?;
|
200
|
-
@
|
200
|
+
@node.xpath_fast('*').length == 0 && @node.xpath_fast("string(text())") != '';
|
201
201
|
end
|
202
202
|
def element_only?;
|
203
|
-
@
|
203
|
+
@node.xpath_fast('*').length > 0 && @node.xpath_fast("string(text())") == '';
|
204
204
|
end
|
205
205
|
|
206
|
-
def path; @
|
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; @
|
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 = @
|
217
|
+
doc.root = @node
|
218
218
|
Dom.new(doc)
|
219
219
|
end
|
220
220
|
end
|
data/lib/xml/smart_domtext.rb
CHANGED
@@ -3,23 +3,23 @@ module XML
|
|
3
3
|
class Dom
|
4
4
|
|
5
5
|
class Text
|
6
|
-
def initialize(text); @
|
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; @
|
12
|
-
def to_f; @
|
13
|
-
def to_i; @
|
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; @
|
16
|
-
def text=(t); @
|
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(@
|
18
|
+
def parent; Node.new(@node.parent); end
|
19
19
|
|
20
|
-
def path; @
|
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
|
-
@
|
6
|
+
@node = element
|
7
7
|
end
|
8
8
|
|
9
9
|
def ===(cls); self.is_a? cls; end
|
10
10
|
|
11
|
-
def dump; @
|
11
|
+
def dump; @node.to_s; end
|
12
12
|
|
13
13
|
def replace_by(n)
|
14
14
|
case n
|
15
|
-
when ProcessingInstruction; ProcessingInstruction.new @
|
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 @
|
21
|
+
def qname; QName.new @node; end
|
22
22
|
|
23
|
-
def content; @
|
24
|
-
def content=(t); @
|
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(@
|
27
|
+
Dom::smart_helper(@node.parent)
|
28
28
|
end
|
29
|
-
def parent?; !@
|
29
|
+
def parent?; !@node.parent.nil?; end
|
30
30
|
|
31
|
-
def path; @
|
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; @
|
38
|
+
def unique_id; @node.pointer_id; end
|
39
39
|
end
|
40
40
|
end
|
41
41
|
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.
|
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.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juergen eTM Mangler
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: example
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
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/
|
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
|