xml-smart 0.5.3 → 0.5.4
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 +4 -4
- data/README.md +30 -8
- data/example/EXAMPLE.xml +3 -3
- data/example/xpath_query +58 -0
- data/example/xpath_visual +27 -1
- data/lib/xml/smart_domnamespace.rb +2 -2
- data/xml-smart.gemspec +2 -2
- metadata +22 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 89bb520809484997c7c349362334186a72cd2b5435173098b0ebf618e87de127
|
|
4
|
+
data.tar.gz: 993ec58b183c6c42b0454870f4861b093269fdc753e54b3ce9fd42d5fdaa2757
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 62825a219a05a79d1f48c4f0f8ea2600013c2e65d99b171b5a023758293742b1122c29f0dc9a305e6b54b21217630e1cfef5cf4d9210d5ec4862d2c81c21f4c6
|
|
7
|
+
data.tar.gz: 77521b72771ba747998f001a6d8c5a841ef8ae8c7c399903670485fb7e57a69791a8ca63d9da967ccf8e0c06769008d7aaf873cb81c7e27cd49a50cd6a35a998
|
data/README.md
CHANGED
|
@@ -12,6 +12,22 @@ This program is distributed without any warranty. See the file 'COPYING' for det
|
|
|
12
12
|
- Thus works for MRI ruby 1.8.7, 1.9.x, JRuby (basically everything that is Nokogiri ready)
|
|
13
13
|
- Works on Linux, OSX, Windows
|
|
14
14
|
|
|
15
|
+
|
|
16
|
+
Fedora:
|
|
17
|
+
```bash
|
|
18
|
+
sudo dnf install @buildsys-build @development-tools @c-development ruby-devel libxml2-devel libxslt-devel zlib-devel libicu-devel libffi-devel
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Ubuntu:
|
|
22
|
+
```bash
|
|
23
|
+
sudo apt install build-essential ruby-dev libxml2-dev libxslt-dev libz-dev libssl-dev libicu-dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Afterwards:
|
|
27
|
+
```bash
|
|
28
|
+
gem install --user xml-smart
|
|
29
|
+
```
|
|
30
|
+
|
|
15
31
|
## Features
|
|
16
32
|
|
|
17
33
|
### Principle of least surprise
|
|
@@ -31,19 +47,23 @@ Sorry, no css selectors, html, ... go to Nokogiri if you look for these.
|
|
|
31
47
|
Use namespaces in xpaths without any additional work:
|
|
32
48
|
|
|
33
49
|
```ruby
|
|
50
|
+
require 'xml/smart'
|
|
51
|
+
|
|
34
52
|
doc = XML::Smart.string('<test xmlns:aaa="uri:aaa"><aaa:test/></test>')
|
|
35
53
|
doc.find('string(aaa:test)')
|
|
36
54
|
doc.close
|
|
37
|
-
```
|
|
55
|
+
```
|
|
38
56
|
|
|
39
57
|
Register your own shortcusts to be available in all XPaths:
|
|
40
58
|
|
|
41
59
|
```ruby
|
|
60
|
+
require 'xml/smart'
|
|
61
|
+
|
|
42
62
|
doc = XML::Smart.string('<test xmlns:aaa="uri:aaa"><aaa:test/></test>')
|
|
43
63
|
doc.register_namespace :a, 'uri:aaa'
|
|
44
64
|
doc.find('string(a:test)')
|
|
45
65
|
doc.close
|
|
46
|
-
```
|
|
66
|
+
```
|
|
47
67
|
|
|
48
68
|
### NFS safe file locking while editing / reading from an XML file
|
|
49
69
|
|
|
@@ -51,7 +71,7 @@ Register your own shortcusts to be available in all XPaths:
|
|
|
51
71
|
XML::Smart.modify("EXAMPLE.xml","<test><names/></test>") do |doc|
|
|
52
72
|
doc.root.add "test_node"
|
|
53
73
|
end
|
|
54
|
-
```
|
|
74
|
+
```
|
|
55
75
|
|
|
56
76
|
### check against relaxng and xml schema
|
|
57
77
|
|
|
@@ -61,12 +81,14 @@ positive results, although it is a lie. XML::Smart internally converts
|
|
|
61
81
|
xml-schema to relaxng, thus allowing for seamless schema usage:
|
|
62
82
|
|
|
63
83
|
```ruby
|
|
84
|
+
require 'xml/smart'
|
|
85
|
+
|
|
64
86
|
doc = XML::Smart.string('<test xmlns:aaa="uri:aaa"><aaa:test/></test>')
|
|
65
87
|
doc.validate_against(XML::Smart.open_unprotected('xmlschema.xml'))
|
|
66
88
|
doc.validate_against(XML::Smart.open_unprotected('xmlschema.xml'))
|
|
67
89
|
doc.find('string(a:test)')
|
|
68
90
|
doc.close
|
|
69
|
-
```
|
|
91
|
+
```
|
|
70
92
|
|
|
71
93
|
### xinclude
|
|
72
94
|
|
|
@@ -75,13 +97,13 @@ https://github.com/sparklemotion/nokogiri/issues/1321), but for now we do suppor
|
|
|
75
97
|
|
|
76
98
|
```ruby
|
|
77
99
|
doc.xinclude!
|
|
78
|
-
```
|
|
100
|
+
```
|
|
79
101
|
|
|
80
102
|
or
|
|
81
|
-
|
|
82
|
-
```ruby
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
83
105
|
doc.find('//someelement').first.xinclude!
|
|
84
|
-
```
|
|
106
|
+
```
|
|
85
107
|
|
|
86
108
|
## Changes since 0.2.x (see Changelog)
|
|
87
109
|
|
data/example/EXAMPLE.xml
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<Customers>
|
|
1
|
+
<Customers xmlns='httsp://ga-a' xmlns:ga-b='bbbb'>
|
|
2
2
|
<Customer ID="1">
|
|
3
3
|
Queen Falafel
|
|
4
|
-
<Address>Stollgasse</Address>
|
|
4
|
+
<ga-b:Address>Stollgasse</ga-b:Address>
|
|
5
5
|
</Customer>
|
|
6
6
|
<Customer ID="2">
|
|
7
7
|
Queen Falafel
|
|
8
|
-
<Address>Wagramerstrasse</Address>
|
|
8
|
+
<ga-b:Address>Wagramerstrasse</ga-b:Address>
|
|
9
9
|
</Customer>
|
|
10
10
|
</Customers>
|
data/example/xpath_query
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require_relative "../lib/xml/smart"
|
|
4
|
+
|
|
5
|
+
def help
|
|
6
|
+
puts "Usage: xpath_query FILE [\"XPATH\" || --prefixes]"
|
|
7
|
+
puts
|
|
8
|
+
puts ' For default namespaces use the last word the namespace name'
|
|
9
|
+
puts ' as prefix, e.g., "//ga-a:*" and "//ga-b:*" for'
|
|
10
|
+
puts ' <Customers xmlns="httsp://ga-a" xmlns:ga-b="bbbb">'
|
|
11
|
+
exit
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
if ARGV.length < 2
|
|
15
|
+
help
|
|
16
|
+
else
|
|
17
|
+
# xpath expression that should be visualised
|
|
18
|
+
xpath = ARGV[1..-1].join(' ') || "/"
|
|
19
|
+
unless File.exist?(ARGV[0])
|
|
20
|
+
help
|
|
21
|
+
end
|
|
22
|
+
doc = XML::Smart.open_unprotected(ARGV[0])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
begin
|
|
26
|
+
prefixes = []
|
|
27
|
+
doc.find('//namespace::*').each do |e|
|
|
28
|
+
if e.prefix != 'xml'
|
|
29
|
+
if e.prefix == ''
|
|
30
|
+
prefixes << [e.href.match(/([a-zA-Z_-]*)[\/.0-9]*$/)[1], e.href]
|
|
31
|
+
else
|
|
32
|
+
prefixes << [e.prefix, e.href]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
if xpath == '--prefixes'
|
|
38
|
+
prefixes.uniq.each do |p|
|
|
39
|
+
puts p[0] + ': ' + p[1]
|
|
40
|
+
end
|
|
41
|
+
exit
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
prefixes.uniq.each do |p|
|
|
45
|
+
doc.register_namespace *p
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
tmp = doc.find(xpath)
|
|
49
|
+
if tmp === XML::Smart::Dom::NodeSet
|
|
50
|
+
tmp.each do |e|
|
|
51
|
+
puts e.dump rescue e.to_s
|
|
52
|
+
end
|
|
53
|
+
else
|
|
54
|
+
puts tmp
|
|
55
|
+
end
|
|
56
|
+
rescue
|
|
57
|
+
puts "Invalid XPath!"
|
|
58
|
+
end
|
data/example/xpath_visual
CHANGED
|
@@ -31,7 +31,11 @@ def prnTree(node,depth,mixed)
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def help
|
|
34
|
-
puts "Usage: xpath_visual FILE
|
|
34
|
+
puts "Usage: xpath_visual FILE[\"XPATH\" || --prefixes]"
|
|
35
|
+
puts
|
|
36
|
+
puts ' For default namespaces use the last word the namespace name'
|
|
37
|
+
puts ' as prefix, e.g., "//ga-a:*" and "//ga-b:*" for'
|
|
38
|
+
puts ' <Customers xmlns="httsp://ga-a" xmlns:ga-b="bbbb">'
|
|
35
39
|
exit
|
|
36
40
|
end
|
|
37
41
|
|
|
@@ -50,6 +54,28 @@ end
|
|
|
50
54
|
@remember = []
|
|
51
55
|
message = ''
|
|
52
56
|
begin
|
|
57
|
+
prefixes = []
|
|
58
|
+
doc.find('//namespace::*').each do |e|
|
|
59
|
+
if e.prefix != 'xml'
|
|
60
|
+
if e.prefix == ''
|
|
61
|
+
prefixes << [e.href.match(/([a-zA-Z_-]*)[\/.0-9]*$/)[1], e.href]
|
|
62
|
+
else
|
|
63
|
+
prefixes << [e.prefix, e.href]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
if xpath == '--prefixes'
|
|
69
|
+
prefixes.uniq.each do |p|
|
|
70
|
+
puts p[0] + ': ' + p[1]
|
|
71
|
+
end
|
|
72
|
+
exit
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
prefixes.uniq.each do |p|
|
|
76
|
+
doc.register_namespace *p
|
|
77
|
+
end
|
|
78
|
+
|
|
53
79
|
tmp = doc.find(xpath)
|
|
54
80
|
if tmp === XML::Smart::Dom::NodeSet
|
|
55
81
|
@remember = doc.find(xpath).collect { |n| n.path }
|
|
@@ -16,7 +16,7 @@ module XML
|
|
|
16
16
|
if @ns.prefix
|
|
17
17
|
@ns.prefix
|
|
18
18
|
else
|
|
19
|
-
@ns.document.custom_namespace_prefixes.find{|k,v| v == @ns.href}[0]
|
|
19
|
+
@ns.document.custom_namespace_prefixes.find{|k,v| v == @ns.href}[0] rescue ''
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -26,7 +26,7 @@ module XML
|
|
|
26
26
|
to_s == other.to_s
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
end
|
data/xml-smart.gemspec
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "xml-smart"
|
|
3
|
-
s.version = "0.5.
|
|
3
|
+
s.version = "0.5.4"
|
|
4
4
|
s.platform = Gem::Platform::RUBY
|
|
5
|
-
s.license = "LGPL-3.0"
|
|
5
|
+
s.license = "LGPL-3.0-or-later"
|
|
6
6
|
s.summary = "An xml library that doesn't suck (for me) - since 2004."
|
|
7
7
|
|
|
8
8
|
s.description = "An xml library that doesn't suck (since 2004). Based on Nokogiri since 2012. For more info check out the Documentation link below."
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: xml-smart
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Juergen eTM Mangler
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: example
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: nokogiri
|
|
@@ -85,6 +84,7 @@ files:
|
|
|
85
84
|
- Rakefile
|
|
86
85
|
- example/CARD.xml
|
|
87
86
|
- example/EXAMPLE.xml
|
|
87
|
+
- example/xpath_query
|
|
88
88
|
- example/xpath_visual
|
|
89
89
|
- lib/xml/XSDtoRNG.xsl
|
|
90
90
|
- lib/xml/smart.rb
|
|
@@ -147,9 +147,8 @@ files:
|
|
|
147
147
|
- xml-smart.gemspec
|
|
148
148
|
homepage: https://github.com/etm/xml-smart/
|
|
149
149
|
licenses:
|
|
150
|
-
- LGPL-3.0
|
|
150
|
+
- LGPL-3.0-or-later
|
|
151
151
|
metadata: {}
|
|
152
|
-
post_install_message:
|
|
153
152
|
rdoc_options: []
|
|
154
153
|
require_paths:
|
|
155
154
|
- lib
|
|
@@ -164,11 +163,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
164
163
|
- !ruby/object:Gem::Version
|
|
165
164
|
version: '0'
|
|
166
165
|
requirements: []
|
|
167
|
-
rubygems_version: 3.
|
|
168
|
-
signing_key:
|
|
166
|
+
rubygems_version: 3.6.9
|
|
169
167
|
specification_version: 4
|
|
170
168
|
summary: An xml library that doesn't suck (for me) - since 2004.
|
|
171
169
|
test_files:
|
|
170
|
+
- minitest/performancereporter_plugin.rb
|
|
171
|
+
- test/1.xml
|
|
172
|
+
- test/2.xml
|
|
173
|
+
- test/3.xml
|
|
174
|
+
- test/EXAMPLE-NS.xml
|
|
175
|
+
- test/EXAMPLE-NSE.xml
|
|
176
|
+
- test/EXAMPLE.str.xml
|
|
177
|
+
- test/EXAMPLE.tmp.xml
|
|
178
|
+
- test/EXAMPLE.xml
|
|
179
|
+
- test/HELLO-MORE.xml
|
|
180
|
+
- test/HELLO.rng
|
|
181
|
+
- test/HELLO.xml
|
|
182
|
+
- test/HELLO.xsd
|
|
183
|
+
- test/XSL_BASE.xml
|
|
184
|
+
- test/XSL_DOCUMENT.xml
|
|
185
|
+
- test/concurrent.xml
|
|
186
|
+
- test/smartrunner.rb
|
|
172
187
|
- test/tc_add.rb
|
|
173
188
|
- test/tc_basic.rb
|
|
174
189
|
- test/tc_concurrent.rb
|
|
@@ -197,20 +212,3 @@ test_files:
|
|
|
197
212
|
- test/tc_xpath_functions.rb
|
|
198
213
|
- test/tc_xpath_root.rb
|
|
199
214
|
- test/tc_xsl.rb
|
|
200
|
-
- test/1.xml
|
|
201
|
-
- test/2.xml
|
|
202
|
-
- test/3.xml
|
|
203
|
-
- test/EXAMPLE-NS.xml
|
|
204
|
-
- test/EXAMPLE-NSE.xml
|
|
205
|
-
- test/EXAMPLE.str.xml
|
|
206
|
-
- test/EXAMPLE.tmp.xml
|
|
207
|
-
- test/EXAMPLE.xml
|
|
208
|
-
- test/HELLO-MORE.xml
|
|
209
|
-
- test/HELLO.xml
|
|
210
|
-
- test/XSL_BASE.xml
|
|
211
|
-
- test/XSL_DOCUMENT.xml
|
|
212
|
-
- test/concurrent.xml
|
|
213
|
-
- test/HELLO.rng
|
|
214
|
-
- test/HELLO.xsd
|
|
215
|
-
- test/smartrunner.rb
|
|
216
|
-
- minitest/performancereporter_plugin.rb
|