validate_xml_xsi 0.1.4 → 0.2.0
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/CHANGELOG.md +4 -0
- data/lib/validate_xml_xsi.rb +14 -15
- data/validate_xml_xsi.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fa9e060212c9992fc22333d6858d9005c0f0be545a1f921c2324fda0071a634
|
4
|
+
data.tar.gz: 880b5e1af35f7cfb1f7c71f09b7fd676632bf921c3ecd5af657c6ce0e4b36df6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63187e958fc288c4722444b0b73464a8af4f94776516dd619feb33bc9cbafbdc69dfca7c72fe7184a95c7014a838fbf10245db6d126d4beea1f04049573ef7f8
|
7
|
+
data.tar.gz: '0975b1be594880e516af4b8a0e758c50eec6c1d4d92621d4e3c870cfcdddde2c1f32973812f3ff4167832958d62f8bb2afb1563db462557904e2b8471c12e3e4'
|
data/CHANGELOG.md
CHANGED
data/lib/validate_xml_xsi.rb
CHANGED
@@ -1,18 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'nokogiri'
|
3
3
|
|
4
|
-
class
|
5
|
-
class Validation
|
6
|
-
class Error
|
7
|
-
Params = [:type, :file, :line, :column, :message, :err]
|
8
|
-
attr_reader *Params, :description
|
9
|
-
def initialize(*args)
|
10
|
-
Params.each.with_index { |param, idx| instance_variable_set("@#{param.to_s}", args[idx]) }
|
11
|
-
@description = "#{@type.to_s} ERROR [#{@file}:#{@line}:#{@column}]: #{@message}".freeze
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
4
|
+
class XML_XSI
|
16
5
|
def self.parse(obj)
|
17
6
|
filename = nil
|
18
7
|
obj = File::read(filename = obj) if obj.is_a?(String) && File::exist?(obj)
|
@@ -23,8 +12,18 @@ class XML
|
|
23
12
|
end
|
24
13
|
|
25
14
|
class Schema
|
15
|
+
class ValidationError < StandardError
|
16
|
+
Params = [:type, :file, :line, :column, :message, :err]
|
17
|
+
attr_reader *Params, :description
|
18
|
+
def initialize(*args)
|
19
|
+
Params.each.with_index { |param, idx| instance_variable_set("@#{param.to_s}", args[idx]) }
|
20
|
+
@description = "#{@type.to_s} ERROR [#{@file}:#{@line}:#{@column}]: #{@message}".freeze
|
21
|
+
super(@description)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
26
25
|
def self.validate(xml_doc)
|
27
|
-
xml_doc =
|
26
|
+
xml_doc = XML_XSI::parse(xml_doc) unless xml_doc.is_a?(Nokogiri::XML::Document)
|
28
27
|
errors = []
|
29
28
|
## Build an all-in-one XSD document that imports all of the separate schema locations
|
30
29
|
xsd_doc = "<?xml version=\"1.0\"?>\n"
|
@@ -52,13 +51,13 @@ class XML
|
|
52
51
|
xsd = Nokogiri::XML.Schema(xsd_doc)
|
53
52
|
xsd.errors.each do |err|
|
54
53
|
err_msg = (/ERROR: /.match(err.message)) ? $' : err.message
|
55
|
-
errors <<
|
54
|
+
errors << ValidationError.new(:XSD, err.file, err.line, err.column, err_msg, err)
|
56
55
|
end
|
57
56
|
errs = xsd.validate(xml_doc)
|
58
57
|
errs.each do |err|
|
59
58
|
err_msg = (/ERROR: /.match(err.message)) ? $' : err.message
|
60
59
|
fname = (err.file.nil?) ? xml_doc.filename : err.file
|
61
|
-
errors <<
|
60
|
+
errors << ValidationError.new(:XML, fname, err.line, err.column, err_msg, err)
|
62
61
|
end
|
63
62
|
errors
|
64
63
|
end
|
data/validate_xml_xsi.gemspec
CHANGED