flazz-schematron 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +14 -0
- data/bin/validate +57 -0
- data/bin/validate-sh +9 -0
- data/schematron.gemspec +14 -0
- metadata +56 -0
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.libs << 'spec'
|
8
|
+
t.spec_opts << "--color"
|
9
|
+
# t.warning = true
|
10
|
+
# t.rcov = true
|
11
|
+
# t.rcov_opts += ["-x /Library", "-x spec"]
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => [:spec]
|
data/bin/validate
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'libxml'
|
4
|
+
require 'libxslt'
|
5
|
+
|
6
|
+
include LibXML
|
7
|
+
include LibXSLT
|
8
|
+
|
9
|
+
# The location of the ISO schematron implemtation lives
|
10
|
+
# Change this as needed
|
11
|
+
ISO_IMPL_DIR = 'iso_impl'
|
12
|
+
|
13
|
+
# The file names of the compilation stages
|
14
|
+
ISO_FILES = [ 'iso_dsdl_include.xsl',
|
15
|
+
'iso_abstract_expand.xsl',
|
16
|
+
'iso_svrl.xsl' ]
|
17
|
+
|
18
|
+
# Namespace prefix declarations for use in XPaths
|
19
|
+
NS_PREFIXES = {
|
20
|
+
'svrl' => 'http://purl.oclc.org/dsdl/svrl'
|
21
|
+
}
|
22
|
+
|
23
|
+
# Tell the parse to remember the line numbers for each node
|
24
|
+
XML::Parser::default_line_numbers = true
|
25
|
+
|
26
|
+
# Get sch and xml from command line
|
27
|
+
schema_doc = XML::Document.file ARGV[0]
|
28
|
+
instance_doc = XML::Document.file ARGV[1]
|
29
|
+
|
30
|
+
# Compile schematron into xsl that maps to svrl
|
31
|
+
xforms = ISO_FILES.map do |file|
|
32
|
+
|
33
|
+
Dir.chdir(ISO_IMPL_DIR) do
|
34
|
+
doc = XML::Document.file file
|
35
|
+
XSLT::Stylesheet.new doc
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
validator_doc = xforms.inject(schema_doc) { |xml, xsl| xsl.apply xml }
|
41
|
+
validator_xsl = XSLT::Stylesheet.new validator_doc
|
42
|
+
|
43
|
+
# Validate the xml
|
44
|
+
results_doc = validator_xsl.apply instance_doc
|
45
|
+
|
46
|
+
# Print the errors
|
47
|
+
results_doc.root.find('//svrl:failed-assert', NS_PREFIXES).each do |assert|
|
48
|
+
context = instance_doc.root.find_first assert['location']
|
49
|
+
|
50
|
+
assert.find('svrl:text/text()', NS_PREFIXES).each do |message|
|
51
|
+
puts '%s "%s" on line %d: %s' % [ context.node_type_name,
|
52
|
+
context.name,
|
53
|
+
context.line_num,
|
54
|
+
message.content.strip ]
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/bin/validate-sh
ADDED
data/schematron.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "schematron"
|
3
|
+
spec.version = '0.0.0'
|
4
|
+
spec.summary = "ISO Schematron Validation"
|
5
|
+
spec.email = "flazzarino@gmail.com"
|
6
|
+
spec.homepage = 'http://github.com/flazz/iso-schematron'
|
7
|
+
spec.authors = ["Francesco Lazzarino"]
|
8
|
+
|
9
|
+
spec.files = ["Rakefile", "schematron.gemspec",
|
10
|
+
"bin/validate",
|
11
|
+
"bin/validate-sh"]
|
12
|
+
|
13
|
+
spec.has_rdoc = true
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flazz-schematron
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francesco Lazzarino
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-25 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: flazzarino@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- Rakefile
|
26
|
+
- schematron.gemspec
|
27
|
+
- bin/validate
|
28
|
+
- bin/validate-sh
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://github.com/flazz/iso-schematron
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.2.0
|
52
|
+
signing_key:
|
53
|
+
specification_version: 2
|
54
|
+
summary: ISO Schematron Validation
|
55
|
+
test_files: []
|
56
|
+
|