A method to copy namespaces declarations. - Java javax.xml.soap

Java examples for javax.xml.soap:SOAPMessage

Description

A method to copy namespaces declarations.

Demo Code

/****************************************************************************
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL///from   w w w.j  a va  2 s  .co  m

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is TEAM Engine.

The Initial Developer of the Original Code is Intecs SPA.  Portions created by
Intecs SPA are Copyright (C) 2008-2009, Intecs SPA. All Rights Reserved.

Contributor(s): No additional contributors to date
 ****************************************************************************/
//package com.java2s;

import org.w3c.dom.Attr;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

public class Main {
    /**
     * 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
     */
    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());
            }
        }
    }
}

Related Tutorials