Class: Uniword::Validation::Validators::XmlSchemaValidator
- Inherits:
-
LayerValidator
- Object
- LayerValidator
- Uniword::Validation::Validators::XmlSchemaValidator
- Defined in:
- lib/uniword/validation/validators/xml_schema_validator.rb
Overview
Validates XML schema — well-formedness and XSD schema validity.
This is Layer 4 validation. Two modes:
-
Well-formedness: all XML parts parse without errors
-
XSD validation: parts validated against OOXML XSD schemas
XSD validation uses SchemaRegistry for namespace-aware schema selection. Uses Moxml for namespace detection and Nokogiri::XML::Schema for validation.
Instance Attribute Summary
Attributes inherited from LayerValidator
Instance Method Summary collapse
Methods inherited from LayerValidator
Constructor Details
This class inherits a constructor from Uniword::Validation::LayerValidator
Instance Method Details
#layer_name ⇒ Object
25 26 27 |
# File 'lib/uniword/validation/validators/xml_schema_validator.rb', line 25 def layer_name "XSD Schema" end |
#validate(path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/uniword/validation/validators/xml_schema_validator.rb', line 29 def validate(path) issues = [] Zip::File.open(path) do |zip| xml_entries = zip.entries.select { |e| e.name.end_with?(".xml") } if xml_entries.empty? issues << Report::ValidationIssue.new( severity: "error", code: "XSD-001", message: "No XML files found in document", suggestion: "A valid DOCX must contain at least [Content_Types].xml.", ) return build_result(issues) end xml_entries.each do |entry| validate_entry(entry, issues) end validate_schemas(zip, xml_entries, issues) if xsd_validation? end build_result(issues) rescue Zip::Error => e issues << Report::ValidationIssue.new( severity: "error", code: "XSD-001", message: "Cannot open ZIP file: #{e.}", ) build_result(issues) end |