Class: Lutaml::Xsd::Validation::Rules::ContentModelValidationRule

Inherits:
ValidationRule
  • Object
show all
Defined in:
lib/lutaml/xsd/validation/rules/content_model_validation_rule.rb

Overview

ContentModelValidationRule validates content models

This rule checks:

  • xs:sequence (order matters)

  • xs:choice (one of alternatives)

  • xs:all (all must appear, order doesn’t matter)

  • Nested sequences/choices

Based on Jing validator content model validation algorithm.

Examples:

Using the rule

rule = ContentModelValidationRule.new
rule.validate(xml_element, complex_type, collector)

See Also:

  • Content Model 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)

    :structure



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

def category
  :structure
end

#descriptionString

Rule description

Returns:

  • (String)


35
36
37
# File 'lib/lutaml/xsd/validation/rules/content_model_validation_rule.rb', line 35

def description
  "Validates element content models (sequence, choice, all)"
end

#validate(xml_element, schema_def, collector) ⇒ void

This method returns an undefined value.

Validate content model

Validates element children against the schema’s content model, ensuring correct order (sequence), alternatives (choice), or completeness (all).

Parameters:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/lutaml/xsd/validation/rules/content_model_validation_rule.rb', line 50

def validate(xml_element, schema_def, collector)
  return unless schema_def

  # Resolve content model
  content_model = resolve_content_model(schema_def)
  return unless content_model

  # Validate based on content model type
  case content_model
  when Lutaml::Xsd::Sequence
    validate_sequence(xml_element, content_model, collector)
  when Lutaml::Xsd::Choice
    validate_choice(xml_element, content_model, collector)
  when Lutaml::Xsd::All
    validate_all(xml_element, content_model, collector)
  end
end