Class: Lutaml::Xsd::Validation::Rules::AttributeValidationRule
- Inherits:
-
ValidationRule
- Object
- ValidationRule
- Lutaml::Xsd::Validation::Rules::AttributeValidationRule
- Defined in:
- lib/lutaml/xsd/validation/rules/attribute_validation_rule.rb
Overview
AttributeValidationRule validates element attributes
This rule checks:
-
Required attributes are present
-
Attribute values match schema definitions
-
No unexpected attributes exist
-
Attribute types are valid
Based on Jing validator attribute validation algorithm.
Constant Summary
Constants inherited from ValidationRule
Instance Attribute Summary
Attributes inherited from ValidationRule
Instance Method Summary collapse
-
#category ⇒ Symbol
Rule category.
-
#description ⇒ String
Rule description.
-
#validate(xml_element, schema_element, collector) ⇒ void
Validate element attributes.
Methods inherited from ValidationRule
#applicable?, #disable!, #enable!, #enabled?, #initialize, #inspect, #option, #priority, #to_h, #to_s
Constructor Details
This class inherits a constructor from Lutaml::Xsd::Validation::ValidationRule
Instance Method Details
#category ⇒ Symbol
Rule category
28 29 30 |
# File 'lib/lutaml/xsd/validation/rules/attribute_validation_rule.rb', line 28 def category :constraint end |
#description ⇒ String
Rule description
35 36 37 |
# File 'lib/lutaml/xsd/validation/rules/attribute_validation_rule.rb', line 35 def description "Validates element attributes against schema definitions" end |
#validate(xml_element, schema_element, collector) ⇒ void
This method returns an undefined value.
Validate element attributes
Validates all attributes of an XML element against the schema definition, checking presence of required attributes, validity of values, and absence of unexpected attributes.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/lutaml/xsd/validation/rules/attribute_validation_rule.rb', line 50 def validate(xml_element, schema_element, collector) return unless schema_element schema_attributes = collect_schema_attributes(schema_element) xml_attributes = xml_element.attributes # Step 1: Check required attributes are present validate_required_attributes(xml_element, schema_attributes, xml_attributes, collector) # Step 2: Validate attribute values validate_attribute_values(xml_element, schema_attributes, xml_attributes, collector) # Step 3: Check for unexpected attributes validate_no_unexpected_attributes(xml_element, schema_attributes, xml_attributes, collector) end |