flazz-schematron 0.0.3 → 0.1.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.
- data/lib/schematron.rb +14 -6
- data/schematron.gemspec +1 -1
- data/spec/schema/pim.sch +9 -1
- data/spec/schema_spec.rb +16 -0
- metadata +3 -2
data/lib/schematron.rb
CHANGED
@@ -43,23 +43,31 @@ module Schematron
|
|
43
43
|
# Validate the xml
|
44
44
|
results_doc = @validator_xsl.apply instance_doc
|
45
45
|
|
46
|
-
# compile the errors
|
46
|
+
# compile the errors and log any messages
|
47
|
+
rule_hits(results_doc, instance_doc, 'assert', '//svrl:failed-assert') +
|
48
|
+
rule_hits(results_doc, instance_doc, 'report', '//svrl:successful-report')
|
49
|
+
end
|
50
|
+
|
51
|
+
# Look for reported or failed rules of a particular type in the instance doc
|
52
|
+
def rule_hits(results_doc, instance_doc, rule_type, xpath)
|
53
|
+
|
47
54
|
results = []
|
48
55
|
|
49
|
-
results_doc.root.find(
|
50
|
-
context = instance_doc.root.find_first
|
51
|
-
|
52
|
-
|
56
|
+
results_doc.root.find(xpath, NS_PREFIXES).each do |hit|
|
57
|
+
context = instance_doc.root.find_first hit['location']
|
58
|
+
|
59
|
+
hit.find('svrl:text/text()', NS_PREFIXES).each do |message|
|
53
60
|
results << {
|
61
|
+
:rule_type => rule_type,
|
54
62
|
:type => context.node_type_name,
|
55
63
|
:name => context.name,
|
56
64
|
:line => context.line_num,
|
57
65
|
:message => message.content.strip }
|
58
66
|
end
|
59
|
-
|
60
67
|
end
|
61
68
|
|
62
69
|
results
|
70
|
+
|
63
71
|
end
|
64
72
|
|
65
73
|
end
|
data/schematron.gemspec
CHANGED
data/spec/schema/pim.sch
CHANGED
@@ -22,6 +22,14 @@
|
|
22
22
|
</assert>
|
23
23
|
</rule>
|
24
24
|
|
25
|
-
|
25
|
+
</pattern>
|
26
|
+
|
27
|
+
<pattern name="METS should have embedded PREMIS">
|
28
|
+
<rule context="mets:mets">
|
29
|
+
<report test="not(//mets:mdWrap[@MDTYPE='PREMIS'])">
|
30
|
+
This METS file has no embedded PREMIS
|
31
|
+
</report>
|
32
|
+
</rule>
|
33
|
+
</pattern>
|
26
34
|
|
27
35
|
</schema>
|
data/spec/schema_spec.rb
CHANGED
@@ -40,4 +40,20 @@ describe Schematron::Schema do
|
|
40
40
|
results.should_not be_empty
|
41
41
|
end
|
42
42
|
|
43
|
+
it "should log report rules in the results" do
|
44
|
+
schema_file = File.join 'spec', 'schema', 'pim.sch'
|
45
|
+
instance_file = File.join 'spec', 'instances', 'daitss-sip', 'Example1.xml'
|
46
|
+
|
47
|
+
schema_doc = XML::Parser.file(schema_file).parse
|
48
|
+
instance_doc = XML::Parser.file(instance_file).parse
|
49
|
+
|
50
|
+
stron = Schematron::Schema.new schema_doc
|
51
|
+
results = stron.validate instance_doc
|
52
|
+
|
53
|
+
results.length.should == 1
|
54
|
+
results.first[:rule_type].should == 'report'
|
55
|
+
|
56
|
+
|
57
|
+
end
|
58
|
+
|
43
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flazz-schematron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Lazzarino
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- spec/spec_helper.rb
|
70
70
|
has_rdoc: false
|
71
71
|
homepage: http://github.com/flazz/iso-schematron
|
72
|
+
licenses:
|
72
73
|
post_install_message:
|
73
74
|
rdoc_options: []
|
74
75
|
|
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
requirements: []
|
90
91
|
|
91
92
|
rubyforge_project: schematron
|
92
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.3.5
|
93
94
|
signing_key:
|
94
95
|
specification_version: 2
|
95
96
|
summary: ISO Schematron Validation
|