Class: Lutaml::Xsd::Validation::Rules::AttributeValidationRule

Inherits:
ValidationRule
  • Object
show all
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.

Examples:

Using the rule

rule = AttributeValidationRule.new
rule.validate(xml_element, schema_element, collector)

See Also:

  • Attribute Validation

Constant Summary

Constants inherited from ValidationRule

ValidationRule::CATEGORIES

Instance Attribute Summary

Attributes inherited from ValidationRule

#options

Instance Method Summary collapse

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

#categorySymbol

Rule category

Returns:

  • (Symbol)

    :constraint



28
29
30
# File 'lib/lutaml/xsd/validation/rules/attribute_validation_rule.rb', line 28

def category
  :constraint
end

#descriptionString

Rule description

Returns:

  • (String)


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.

Parameters:



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