schematron 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +2 -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: 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
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-31 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|