validate_xml_xsi 0.2.0 → 0.2.3

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: 4fa9e060212c9992fc22333d6858d9005c0f0be545a1f921c2324fda0071a634
4
- data.tar.gz: 880b5e1af35f7cfb1f7c71f09b7fd676632bf921c3ecd5af657c6ce0e4b36df6
3
+ metadata.gz: 0fd07518ce27feb3ced81500c73f9ea2ba9a5a760b41e2ae18b905babf740a3f
4
+ data.tar.gz: 509f1417b6c544f48ef3eb1774c75175ffa82613cf24a840dd1dc2a8f4829f03
5
5
  SHA512:
6
- metadata.gz: 63187e958fc288c4722444b0b73464a8af4f94776516dd619feb33bc9cbafbdc69dfca7c72fe7184a95c7014a838fbf10245db6d126d4beea1f04049573ef7f8
7
- data.tar.gz: '0975b1be594880e516af4b8a0e758c50eec6c1d4d92621d4e3c870cfcdddde2c1f32973812f3ff4167832958d62f8bb2afb1563db462557904e2b8471c12e3e4'
6
+ metadata.gz: 7dd88a35fe216d3d02b9cb0de4d672bd309f180ac57595d8ac69abf86304d10550ba8322d402cd065cb89969d25313057ccbc1d64353a4da75dd2c18c7a8e4db
7
+ data.tar.gz: d7fe6994da9bf99d3302be3e8ec88c7168cb4c01d02debcf38560060007c8f2d4a36871e29b08a139636e3c137db7bd283c38fa6fc71c103b605c5059577b988
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## v0.2.3
2
+
3
+ * Rename XML_XSI::Schema::parse_schema to just XML_XSI::Schema::parse
4
+
5
+ ## v0.2.2
6
+
7
+ * Break out parsing of the schema from validation so we can reference the schema if we need to.
8
+
9
+ ## v0.2.1
10
+
11
+ * Update namespace to XML_XSI in bin/validate_xml_xsi utility
12
+
1
13
  ## v0.2.0
2
14
 
3
15
  * Change namespace to XML_XSI and rename/promote Validation::Error to Schema::ValidationError < StandardError.
data/bin/validate_xml_xsi CHANGED
@@ -3,7 +3,7 @@ require 'validate_xml_xsi'
3
3
 
4
4
  while ARGV.size > 0
5
5
  fname = ARGV.shift
6
- errors = XML::Schema::validate(fname)
6
+ errors = XML_XSI::Schema::validate(fname)
7
7
  if errors.empty?
8
8
  puts "XML Schema check complete - NO ERRORS!"
9
9
  else
@@ -12,6 +12,7 @@ class XML_XSI
12
12
  end
13
13
 
14
14
  class Schema
15
+ class DocumentError < StandardError; end
15
16
  class ValidationError < StandardError
16
17
  Params = [:type, :file, :line, :column, :message, :err]
17
18
  attr_reader *Params, :description
@@ -22,9 +23,10 @@ class XML_XSI
22
23
  end
23
24
  end
24
25
 
25
- def self.validate(xml_doc)
26
- xml_doc = XML_XSI::parse(xml_doc) unless xml_doc.is_a?(Nokogiri::XML::Document)
27
- errors = []
26
+ def self.parse(xml_doc)
27
+ unless xml_doc.is_a?(Nokogiri::XML::Document)
28
+ raise DocumentError.new("not a Nokogiri::XML::Document (class: #{xml_doc.class.name})!"
29
+ end
28
30
  ## Build an all-in-one XSD document that imports all of the separate schema locations
29
31
  xsd_doc = "<?xml version=\"1.0\"?>\n"
30
32
  xsd_doc << "<xsd:schema targetNamespace=\"http://www.w3.orig/XML/1998/namespace\"\n" \
@@ -37,7 +39,7 @@ class XML_XSI
37
39
  elem['xsi:schemaLocation'].scan(/(\S+)\s+(\S+)/).each do |ns_set|
38
40
  if ns_loc = schemata_by_ns[ns_set.first]
39
41
  unless ns_loc.eql?(ns_set.last)
40
- error "MISMATCHING XMLNS XSI: #{ns_set.first} -> #{ns_loc} VS #{ns_set.last}"
42
+ raise DocumentError.new("MISMATCHING XMLNS XSI: #{ns_set.first} -> #{ns_loc} VS #{ns_set.last}")
41
43
  end
42
44
  else
43
45
  schemata_by_ns[ns_set.first] = ns_set.last
@@ -48,7 +50,16 @@ class XML_XSI
48
50
  xsd_doc << " <xsd:import namespace=\"#{ns_href}\" schemaLocation=\"#{ns_file}\"/>\n"
49
51
  end
50
52
  xsd_doc << "</xsd:schema>\n"
51
- xsd = Nokogiri::XML.Schema(xsd_doc)
53
+ Nokogiri::XML::Schema.new(xsd_doc)
54
+ end
55
+
56
+ def self.validate(xml_doc, xsd = nil)
57
+ xml_doc = XML_XSI::parse(xml_doc) unless xml_doc.is_a?(Nokogiri::XML::Document)
58
+ errors = []
59
+ unless xsd.nil? || xsd.is_a?(Nokogiri::XML::Schema)
60
+ raise DocumentError.new("Invalid XSD - not a Nokogiri::XML::Schema (class: #{xsd.class.name})!")
61
+ end
62
+ xsd = self.parse_schema(xml_doc) if xsd.nil?
52
63
  xsd.errors.each do |err|
53
64
  err_msg = (/ERROR: /.match(err.message)) ? $' : err.message
54
65
  errors << ValidationError.new(:XSD, err.file, err.line, err.column, err_msg, err)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "validate_xml_xsi"
3
- spec.version = "0.2.0"
3
+ spec.version = "0.2.3"
4
4
  spec.authors = ["David Hansen"]
5
5
  spec.email = ["david@hansen4.net"]
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validate_xml_xsi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Hansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-08 00:00:00.000000000 Z
11
+ date: 2022-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler