code: private String getNamespaceDeclarations() {
          StringBuilder nsDecls = new StringBuilder();
          String quoteStyle = "'";
          for (Iterator keys = ctx.getPrefixes(); keys.hasNext(); ) {
              String prefix = (String) keys.next();
              String uri = ctx.getNamespaceURI(prefix);
              if (uri == null) {
                  continue;
              }
              // this shouldn't have happened, but better safe than sorry
              if (prefix == null) {
                  prefix = "";
              }
  
              if (uri.indexOf('\'') != -1) {
                  quoteStyle = "\"";
              }
              nsDecls.append(' ').append(XMLNS_PREFIX);
              if (prefix.length() > 0) {
                  nsDecls.append(':');
              }
              nsDecls.append(prefix).append('=')
                  .append(quoteStyle).append(uri).append(quoteStyle)
                  .append(' ');
          }
          return nsDecls.toString();
      }
docs: returns namespace declarations for all namespaces known to the
  current context.