• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / tigerdata-app / af16f079-955d-4d7a-a6b5-9dad5da9522e

04 Oct 2024 05:36PM UTC coverage: 84.655% (-0.4%) from 85.062%
af16f079-955d-4d7a-a6b5-9dad5da9522e

Pull #899

circleci

hectorcorrea
Moar documentation
Pull Request #899: First pass at validating an XML document against the TigerData XSD

4 of 4 branches covered (100.0%)

5 of 18 new or added lines in 1 file covered. (27.78%)

2146 of 2535 relevant lines covered (84.65%)

305.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.78
/lib/tasks/xml_schema.rake
1
# frozen_string_literal: true
2
# :nocov:
3
require "nokogiri"
✔
4
namespace :xml_schema do
✔
5
  desc "Validates the example XML provided by Matt against the TigerData XSD"
✔
6
  task validate_example: :environment do
✔
7
    # Files downloaded from https://github.com/pulibrary/tigerdata-app/issues/896
NEW
8
    schema_file = "./lib/assets/TigerData_StandardMetadataSchema_v0.7_2024-08-27.xsd"
×
NEW
9
    document_file = "./lib/assets/TigerData_MetadataExample-Project_2024-08-27.xml"
×
10

NEW
11
    xsd = File.read(schema_file)
×
NEW
12
    xsd = use_local_xml_xsd(xsd)
×
13

14
    # Validate the sample XML file against the schema
15
    # https://www.tutorialspoint.com/xsd/xsd_syntax.htm
16
    # https://nokogiri.org/rdoc/Nokogiri/XML/Schema.html
NEW
17
    xsd = Nokogiri::XML::Schema(xsd)
×
NEW
18
    doc = Nokogiri::XML(File.read(document_file))
×
NEW
19
    errors = xsd.validate(doc)
×
NEW
20
    if errors.count == 0
×
NEW
21
      puts "OK"
×
22
    else
NEW
23
      errors.each do |error|
×
NEW
24
        puts error.message
×
25
      end
26
    end
27
  end
28

29
  # Replace the reference to `xml.xsd` from the xsd with a reference to our
30
  # local copy of the file, otherwise the validation tends to fail because
31
  # Nokogiri cannot load the original `xml.xsd` file from the W3C
32
  # source. ¯\_(ツ)_/¯
33
  # For more information see: https://stackoverflow.com/a/18527198/446681
34
  def use_local_xml_xsd(xsd)
✔
NEW
35
    local_xml_xsd = Pathname.new("./lib/assets/xml.xsd").realpath.to_s
×
NEW
36
    xsd.sub!("https://www.w3.org/2001/xml.xsd", "file://#{local_xml_xsd}")
×
37
  end
38
end
39
# :nocov:
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc