lib/schematron.rb in flazz-schematron-0.0.3 vs lib/schematron.rb in flazz-schematron-0.1.0
- old
+ new
@@ -41,26 +41,34 @@
def validate(instance_doc)
# Validate the xml
results_doc = @validator_xsl.apply instance_doc
- # compile the errors
+ # compile the errors and log any messages
+ rule_hits(results_doc, instance_doc, 'assert', '//svrl:failed-assert') +
+ rule_hits(results_doc, instance_doc, 'report', '//svrl:successful-report')
+ end
+
+ # Look for reported or failed rules of a particular type in the instance doc
+ def rule_hits(results_doc, instance_doc, rule_type, xpath)
+
results = []
- results_doc.root.find('//svrl:failed-assert', NS_PREFIXES).each do |assert|
- context = instance_doc.root.find_first assert['location']
-
- assert.find('svrl:text/text()', NS_PREFIXES).each do |message|
+ results_doc.root.find(xpath, NS_PREFIXES).each do |hit|
+ context = instance_doc.root.find_first hit['location']
+
+ hit.find('svrl:text/text()', NS_PREFIXES).each do |message|
results << {
+ :rule_type => rule_type,
:type => context.node_type_name,
:name => context.name,
:line => context.line_num,
:message => message.content.strip }
end
-
end
results
+
end
end
end