Class: SvgConform::Requirements::NamespaceAttributesRequirement
- Inherits:
-
BaseRequirement
- Object
- Lutaml::Model::Serializable
- BaseRequirement
- SvgConform::Requirements::NamespaceAttributesRequirement
- Defined in:
- lib/svg_conform/requirements/namespace_attributes_requirement.rb
Overview
Validates that elements don’t have attributes from disallowed namespaces or only have attributes from allowed namespaces (whitelist mode)
Instance Method Summary collapse
Methods inherited from BaseRequirement
#collect_sax_data, #element?, #get_attribute, #get_attributes, #has_attribute?, #needs_deferred_validation?, #remove_attribute, #set_attribute, #should_check_node?, #text?, #to_s, #validate_document, #validate_sax_complete
Instance Method Details
#check(node, context) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/svg_conform/requirements/namespace_attributes_requirement.rb', line 28 def check(node, context) return unless element?(node) # Skip validation for exempt elements (e.g., RDF metadata elements) return if exempt_elements.include?(node.name) # Try to get attributes using different methods depending on what's available if node.respond_to?(:attribute_nodes) # Use attribute_nodes if available (Nokogiri style) check_attribute_nodes(node, context) elsif node.respond_to?(:attributes) # Fallback to attributes method (Moxml style) check_attributes_hash(node, context) end end |
#validate_sax_element(element, context) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/svg_conform/requirements/namespace_attributes_requirement.rb', line 44 def validate_sax_element(element, context) # Extract local name without prefix for exemption check local_name = if element.name.include?(":") element.name.split(":", 2).last else element.name end # Skip validation for exempt elements (e.g., RDF metadata elements) return if exempt_elements.include?(local_name) || exempt_elements.include?(element.name) # Check all attributes for namespace violations element.attributes.each do |attr| check_sax_attribute(attr, element, context) end end |