code: 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);
              }
          }
  
      }
docs: Purging unused declarations is less optimal, performance-wise, than never adding them in the
  first place. So, we should still ask the ROME guys to fix their code (not adding dozens of
  unnecessary module declarations). Having said that: purging them here, before XML generation,
  is more efficient than parsing and re-molding the XML after ROME generates it.
  <p/>
  Note that the calling app could still add declarations/modules to the Feed tree after this.
  Which is fine. But those modules are then responsible for crawling to the root of the tree,
  at generate() time, to make sure their namespace declarations are present.