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 ( ) ) ; } } }
A method to copy namespaces declarations .