Skip to content

Instantly share code, notes, and snippets.

@andresamayadiaz
Created January 24, 2013 04:57
Show Gist options
  • Save andresamayadiaz/4617778 to your computer and use it in GitHub Desktop.
Save andresamayadiaz/4617778 to your computer and use it in GitHub Desktop.
Test Validation
def validate
# open("http://www.sat.gob.mx/cfd/3/cfdv32.xsd")
doc = Nokogiri::XML( File.read("/Users/andresamayadiaz/Documents/rails/receptorcfd/public/comp32.xml"), nil, "UTF-8", Nokogiri::XML::ParseOptions::RECOVER )
#puts "KEYS: " + doc.root.keys.to_s
#puts "Schema: " + doc.root["xsi:schemaLocation"]
schemata_by_ns = Hash[ doc.root["xsi:schemaLocation"].scan(/(\S+)\s+(\S+)/) ]
schemata_by_ns.each do |ns,xsd_uri|
xsd = Nokogiri::XML::Schema(open(xsd_uri))
puts "NS: #{ns} --- URI: #{xsd_uri}"
#puts "VALID: " + xsd.valid?(doc).to_s
xsd.validate(doc).each do |error|
puts error.message
end
puts ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment