code: public String getNamespacePrefix(final PrefixMapping mapping,
              final String ns, final boolean compact) {
          final String nsURIPrefix = mapping.getNsURIPrefix(ns);
          if (nsURIPrefix == null) {
              if (compact) {
                  final int hashIdx = ns.lastIndexOf('#');
                  final int split = hashIdx > 0 ? ns.substring(0, hashIdx).lastIndexOf('/') : ns.lastIndexOf('/');
                  return split > 0 ? "..." + ns.substring(split) : ns;
              }
              return ns;
          }
          return nsURIPrefix + ":";
      }
docs: Get the namespace prefix (or the namespace URI itself, if no prefix is
  available) from a prefix mapping
  
  @param mapping the prefix mapping
  @param ns the namespace
  @param compact the boolean value of compact
  @return namespace prefix