Skip to content

Commit

Permalink
errors are reported
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Lazzarino committed Sep 24, 2008
1 parent 4e106a0 commit 9696b7e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
53 changes: 43 additions & 10 deletions bin/validate2.rb
@@ -1,24 +1,57 @@
#!/usr/bin/ruby

require 'libxml'
require 'libxslt'

include LibXML

# TODO make the namespace prefixes transparant
include LibXSLT

XML::Parser::default_line_numbers=true

results_doc = XML::Document.file('output.xml')
instance_doc = XML::Document.file('instances/Example2.xml')
def transform(stylesheet, instance)

# Build the stylesheet
stylesheet = XSLT::Stylesheet.new case stylesheet
when LibXML::XML::Document
stylesheet
when String
XML::Document.file stylesheet
end

# Transform the instance
stylesheet.apply case instance
when LibXML::XML::Document
instance
when String
XML::Document.file instance
end
end

def validate(sch, instance)
p1 = transform 'iso_dsdl_include.xsl', sch
p2 = transform 'iso_abstract_expand.xsl', p1
p3 = transform 'iso_svrl.xsl', p2
transform p3, instance
end

# TODO make the namespace prefixes transparant

instance_doc = XML::Document.file '../instances/Example2.xml'
results_doc = validate '../sch/fda_sip.sch', instance_doc

locations = results_doc.root.find('//svrl:failed-assert').map do |assert|
i_node = instance_doc.root.find_first assert['location']
errors = []
results_doc.root.find('//svrl:failed-assert').each do |assert|
context = instance_doc.root.find_first assert['location']

assert.find('svrl:text/text()').each do |message|
puts '%s "%s" on line %d: %s' % [i_node.node_type_name,
i_node.name,
i_node.line_num,
message.content.strip]
errors << '%s "%s" on line %d: %s' % [ context.node_type_name,
context.name,
context.line_num,
message.content.strip ]
end

end

errors.each do |error|
puts error
end
2 changes: 1 addition & 1 deletion instances/Example2.xml
Expand Up @@ -21,7 +21,7 @@
<!-- must have checksum, checksum type & file location -->
<fileSec>
<fileGrp>
<file ID="file-1" CHECKSUM="259c4fabf48fd8fa664fb7123e4706c3" CHECKSUMTYPE="MD5">
<file ID="file-1" CHECKSUM="259c4fabf48fd8fa664fb7123e470624" CHECKSUMTYPE="MD5">
<FLocat LOCTYPE="URL" xlink:href="xxx/content_file_1"/>
</file>

Expand Down

0 comments on commit 9696b7e

Please sign in to comment.