public final List<Namespace> getNamespacesInScope() {
    // The assumption here is that all namespaces are valid,
    // that there are no namespace collisions on this element

    // This method is also the 'anchor' of the three getNamespaces*() methods
    // It does not make reference to this Element instance's other
    // getNamespace*() methods

    TreeMap<String, Namespace> namespaces = new TreeMap<>();
    namespaces.put(Namespace.XML_NAMESPACE.getPrefix(), Namespace.XML_NAMESPACE);
    namespaces.put(getNamespacePrefix(), getNamespace());
    if (additionalNamespaces != null) {
      for (Namespace ns : getAdditionalNamespaces()) {
        if (!namespaces.containsKey(ns.getPrefix())) {
          namespaces.put(ns.getPrefix(), ns);
        }
      }
    }
    if (attributes != null) {
      for (Attribute att : getAttributes()) {
        Namespace ns = att.getNamespace();
        if (!namespaces.containsKey(ns.getPrefix())) {
          namespaces.put(ns.getPrefix(), ns);
        }
      }
    }
    // Right, we now have all the namespaces that are current on this EElement.
    // Include any other namespaces that are inherited.
    final Element pnt = getParentElement();
    if (pnt != null) {
      for (Namespace ns : pnt.getNamespacesInScope()) {
        if (!namespaces.containsKey(ns.getPrefix())) {
          namespaces.put(ns.getPrefix(), ns);
        }
      }
    }

    if (pnt == null && !namespaces.containsKey("")) {
      // we are the root element, and there is no 'default' namespace.
      namespaces.put(Namespace.NO_NAMESPACE.getPrefix(), Namespace.NO_NAMESPACE);
    }

    List<Namespace> result = new ArrayList<>(namespaces.size());
    result.add(getNamespace());
    namespaces.remove(getNamespacePrefix());
    result.addAll(namespaces.values());
    return result;
  }
public final List<Namespace> getNamespacesInScope()