code: public static void addNSdeclarations(Element source, Element target)
              throws Exception {
          NamedNodeMap sourceAttributes = source.getAttributes();
          Attr attribute;
          String attributeName;
          for (int i = 0; i <= sourceAttributes.getLength() - 1; i++) {
              attribute = (Attr) sourceAttributes.item(i);
              attributeName = attribute.getName();
              if (attributeName.startsWith("xmlns")
                      && !attributeName.startsWith("xmlns:soap-env")) {
                  // System.out.println("XMLNS:" +
                  // attributeName+":"+attribute.getValue());
                  target.setAttribute(attributeName, attribute.getValue());
              }
          }
      }
docs: A method to copy namespaces declarations.
  
  @param source
  the source message containing the namespaces to be copied on
  the target message.
  @param target
  the target message.
  
  @author Simone Gianfranceschi