docs: protected static void purgeUnusedNamespaceDeclarations(final Element root) {
  
          final Set<String> usedPrefixes = new HashSet<String>();
          collectUsedPrefixes(root, usedPrefixes);
  
          final List<Namespace> list = root.getAdditionalNamespaces();
          final List<Namespace> additionalNamespaces = new ArrayList<Namespace>();
          additionalNamespaces.addAll(list); // the duplication will prevent a
          // ConcurrentModificationException
          // below
  
          for (final Namespace ns : additionalNamespaces) {
              final String prefix = ns.getPrefix();
              if (prefix != null && prefix.length() > 0 && !usedPrefixes.contains(prefix)) {
                  root.removeNamespaceDeclaration(ns);
              }
          }
  
      }