xml-smart 0.3.12 → 0.3.14

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
  SHA1:
3
- metadata.gz: be39705fa3c69647ef581c26f96bc40df8073474
4
- data.tar.gz: daf048cf47a87e78342788896a3844fb6f8f22b3
3
+ metadata.gz: 9fa0cb5980990dae96d416b9122d90882d1ef5ae
4
+ data.tar.gz: 26a3c1597a503cee447ab4eccd226d564d34ade5
5
5
  SHA512:
6
- metadata.gz: 2288bb3cd7925f304dc175890c0eccc3637fcd51feff4692e04774f731bc98eae2535d30056cfe83c51ab711b48c2cdd36ca6c2e2b03afc9346a459e0c484c64
7
- data.tar.gz: 7d72f428e5393033c3c353625fcebb56d6fab8f14144e49d06e43eb12101f80f35c137f177002a5341fd322378b270271e43205b8b3b9984bfcb614752ae62ff
6
+ metadata.gz: 1cfd22611b531f7121c314edfcfee7830da6cd69f5e654020b238aad6582e0b08252e0d2885450cec4ac349d3735278c20937d8e8ddea3227b680ad016f31349
7
+ data.tar.gz: 0b52ff70a78c074914b6bda148d02b5ade3cfc19140b8eab1d319d1406f6ca3c95003b350bad97e3bb884ed0a30e717a9285001dc3a56c7667322c921b5862bc
data/README.rdoc CHANGED
@@ -47,6 +47,32 @@ Register your own shortcusts to be available in all XPaths:
47
47
  doc.root.add "test_node"
48
48
  end
49
49
 
50
+ === check against relaxng and xml schema
51
+
52
+ Libxml2, the basis for nokogiri has only partial xml-schema support, but full
53
+ relaxng support. Thus checking against xml-schema with nokogiri may return
54
+ positive results, although it is a lie. XML::Smart internally converts
55
+ xml-schema to relaxng, thus allowing for seamless schema usage:
56
+
57
+ doc = XML::Smart.string('<test xmlns:aaa="uri:aaa"><aaa:test/></test>')
58
+ doc.validate_against(XML::Smart.open_unprotected('xmlschema.xml'))
59
+ doc.validate_against(XML::Smart.open_unprotected('xmlschema.xml'))
60
+ doc.find('string(a:test)')
61
+ doc.close
62
+
63
+ === xinclude
64
+
65
+ Libxml2, the basis for nokogiri does not support https xincludes. Nokogiri may
66
+ impelement this in the future (issue
67
+ https://github.com/sparklemotion/nokogiri/issues/1321), but for now we do
68
+ support it:
69
+
70
+ doc.xinclude!
71
+
72
+ or
73
+
74
+ doc.find('//someelement').first.xinclude!
75
+
50
76
  == Changes since 0.2.x (see Changelog)
51
77
 
52
78
  - qname instead of name
data/example/EXAMPLE.xml CHANGED
@@ -5,7 +5,7 @@
5
5
  <name team="1">J�rgen</name>
6
6
  <name team="1">Michel</name>
7
7
  <name team="1">Raphi</name>
8
- <name team="2">Kathrin <b>Fiedler</b> MBA</name>
8
+ <name xmlns:doc="arrra" soap:team="2">Kathrin <b>Fiedler</b> MBA</name>
9
9
  <name team="5">egon</name>
10
10
  </names>
11
11
  <colors>
data/lib/xml/smart.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'nokogiri'
3
3
  require 'tempfile'
4
+ require 'open-uri'
5
+ require 'openssl'
4
6
 
5
7
  require File.expand_path(File.dirname(__FILE__) + '/smart_qname')
6
8
  require File.expand_path(File.dirname(__FILE__) + '/smart_dom')
@@ -26,6 +28,13 @@ module Nokogiri
26
28
  self
27
29
  end
28
30
 
31
+ def basepath=(path)
32
+ @basepath = File.dirname(path.to_s)
33
+ end
34
+ def basepath
35
+ @basepath || ''
36
+ end
37
+
29
38
  def xpath_fast(path)
30
39
  ns = self.custom_namespace_prefixes.merge(self.document.user_custom_namespace_prefixes)
31
40
  ctx = XPathContext.new(self)
@@ -84,6 +93,26 @@ module Nokogiri
84
93
  ctx.evaluate(path)
85
94
  end
86
95
 
96
+ def do_xinclude_manual(relative_to=nil)
97
+ path = ((relative_to || self.document.basepath.to_s) + '/').sub(/\/+$/,'/')
98
+ ctx = XPathContext.new(self)
99
+ ctx.register_namespaces "xi"=>"http://www.w3.org/2001/XInclude"
100
+ ctx.evaluate('//xi:include').each do |ele|
101
+ name = ele.attributes['href'].value
102
+ name = path + name if name !~ /^(https?:|ftp:)/
103
+ content = open(name,{ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).read
104
+ insert = begin
105
+ Nokogiri::XML::parse(content){|config| config.noblanks.noent.nsclean.strict }.root
106
+ rescue
107
+ content
108
+ end
109
+ x = ele.replace insert
110
+ x.each do |n|
111
+ n.do_xinclude_manual if n.is_a? Nokogiri::XML::Element
112
+ end
113
+ end
114
+ end
115
+
87
116
  def xpath_experimental
88
117
  return NodeSet.new(document) unless document
89
118
  @nsc ||= 0
@@ -119,15 +148,15 @@ module XML
119
148
  io = ::Kernel::open(name,'r+')
120
149
  io.flock(File::LOCK_EX)
121
150
  end
122
- dom = Dom.new Nokogiri::XML::parse(io){|config| config.noblanks.noent.nsclean.strict }
151
+ dom = Dom.new Nokogiri::XML::parse(io){|config| config.noblanks.noent.nsclean.strict }, name
123
152
  io.rewind
124
153
  elsif name.is_a?(String) && !File.exists?(name)
125
154
  MUTEX.synchronize do
126
155
  io = ::Kernel::open(name,'w')
127
156
  io.flock(File::LOCK_EX)
128
157
  end
129
- dom = Smart::string(default)
130
- elsif name.is_a?(IO) || name.is_a?(Tempfile)
158
+ dom = Smart::string(default,name)
159
+ elsif name.is_a?(IO) || name.is_a?(Tempfile)
131
160
  MUTEX.synchronize do
132
161
  io = name
133
162
  io.flock(File::LOCK_EX)
@@ -167,10 +196,17 @@ module XML
167
196
  raise Error, 'first parameter has to be a filename or filehandle' unless name.is_a?(String) || name.is_a?(IO) || name.is_a?(Tempfile)
168
197
  raise Error, 'second parameter has to be an xml string' unless default.is_a?(String) || default.nil?
169
198
  dom = begin
170
- io = name.is_a?(String) ? ::Kernel::open(name) : name
199
+ filename = nil
200
+ io = if name.is_a?(String)
201
+ filename = name
202
+ ::Kernel::open(name)
203
+ else
204
+ filename = name.path
205
+ name
206
+ end
171
207
  begin
172
208
  io.flock(File::LOCK_EX) if lock
173
- Dom.new Nokogiri::XML::parse(io){|config| config.noblanks.noent.nsclean.strict }
209
+ Dom.new Nokogiri::XML::parse(io){|config| config.noblanks.noent.nsclean.strict }, filename
174
210
  ensure
175
211
  io.flock(File::LOCK_UN)
176
212
  end
@@ -190,9 +226,9 @@ module XML
190
226
  end
191
227
  end
192
228
 
193
- def self::string(str)
229
+ def self::string(str,basepath=nil)
194
230
  raise Error, 'first parameter has to be stringable (:to_s)' unless str.is_a?(String)
195
- dom = Dom.new Nokogiri::XML::parse(str.to_s){|config| config.noblanks.noent.nsclean.strict }
231
+ dom = Dom.new Nokogiri::XML::parse(str.to_s){|config| config.noblanks.noent.nsclean.strict }, basepath
196
232
  if block_given?
197
233
  yield dom
198
234
  nil
data/lib/xml/smart_dom.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module XML
2
2
  module Smart
3
3
  class Dom
4
- def initialize(dom)
4
+ def initialize(dom,basepath=nil)
5
5
  @dom = dom
6
+ @dom.basepath = basepath
6
7
  @unformated = false
7
8
  end
8
9
 
@@ -160,11 +160,7 @@ module XML
160
160
  def namespaces; NamespaceSet.new(self,@element); end
161
161
 
162
162
  def xinclude!(basedir=nil)
163
- if basedir.is_a?(String) && File.directory?(basedir)
164
- Dir.chdir(basedir) { @element.do_xinclude Nokogiri::XML::ParseOptions::STRICT }
165
- else
166
- @element.do_xinclude Nokogiri::XML::ParseOptions::STRICT
167
- end
163
+ @element.do_xinclude_manual(basedir)
168
164
  @element.document.custom_namespace_prefixes_update
169
165
  @element.document.ns_update
170
166
  true
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">2015-03-13 11:04:34 +0100</name>
3
+ <name team="0" a="3">2015-07-23 21:37:19 +0200</name>
4
4
  <name team="1">Jürgen</name>
5
5
  <name team="1">Michel</name>
6
6
  <name team="1">Raphi</name>
data/test/concurrent.xml CHANGED
@@ -1 +1,7 @@
1
- <solutions><solution matnr="9906264" name="mangler" secid="1" assessment="16"><question block="1" question="2"/><question block="2" question="4"/><question block="3" question="6"/></solution></solutions>
1
+ <solutions>
2
+ <solution matnr="9906264" name="mangler" secid="1" when="2015-07-23T21:37:19+02:00" assessment="16">
3
+ <question block="1" question="2"/>
4
+ <question block="2" question="4"/>
5
+ <question block="3" question="6"/>
6
+ </solution>
7
+ </solutions>
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.3.12"
3
+ s.version = "0.3.14"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3"
6
6
  s.summary = "An xml library that doesn't suck - since 2004."
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.3.12
4
+ version: 0.3.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri