Class: SvgConform::Remediations::NamespaceAttributeRemediation
- Inherits:
-
BaseRemediation
- Object
- Lutaml::Model::Serializable
- BaseRemediation
- SvgConform::Remediations::NamespaceAttributeRemediation
- Defined in:
- lib/svg_conform/remediations/namespace_attribute_remediation.rb
Overview
Remediation for removing disallowed namespace attributes and declarations
Instance Method Summary collapse
Methods inherited from BaseRemediation
#execute, #should_execute?, #to_s
Instance Method Details
#apply(document, _context) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/svg_conform/remediations/namespace_attribute_remediation.rb', line 23 def apply(document, _context) changes = [] removed_namespaces = Set.new # First pass: remove disallowed namespace attributes document.traverse do |node| next unless element?(node) changes.concat(remove_disallowed_attributes(node, removed_namespaces)) end # Second pass: remove unused namespace declarations # Nokogiri/libxml2 cannot remove namespace declarations via DOM, # so we use string manipulation + reparse if removed_namespaces.any? || disallowed_namespaces.any? changes.concat(remove_namespace_declarations(document, removed_namespaces)) end changes end |