drools-eclipse/org.guvnor.eclipse.webdav/src/interface/org/eclipse/webdav/dom/ElementEditor.java
protected static Namespaces getNamespaces(Element element, Namespaces namespaces, boolean removeDuplicateNSDeclarations) {

        // Create a container to hold the new namespace definitions.
        Namespaces newNamespaces = null;
        if (namespaces == null)
            newNamespaces = new Namespaces();
        else
            newNamespaces = new Namespaces(namespaces);

        Vector oldAttributes = new Vector();

        // For each attribute on the given element.
        NamedNodeMap nodeMap = element.getAttributes();
        for (int i = 0; i < nodeMap.getLength(); ++i) {
            Attr attr = (Attr) nodeMap.item(i);

            // Is it a name space declaration?
            String name = attr.getName();
            if (name.startsWith(XML_PREFIX)) {
                String nsName = attr.getValue();

                // Is it setting or clearing the default namespace?
                // (i.e. has no prefix part)
                if (name.length() == XML_PREFIX.length()) {
                    if (nsName.equals("")) //$NON-NLS-1$
                        newNamespaces.setDefaultNSName(null);
                    else
                        newNamespaces.setDefaultNSName(nsName);
                } else if (name.charAt(XML_PREFIX.length()) == ':') {
                    // It is a namespace declaration.
                    String nsPrefix = name.substring(XML_PREFIX.length() + 1);
                    if (nsPrefix.length() > 0 && nsName.length() > 0) {
                        // Ensure it is in the new namespaces list.
                        newNamespaces.putNSName(nsPrefix, nsName);
                        boolean prefixExists = newNamespaces.getNSPrefix(nsName) != null;
                        if (!prefixExists)
                            newNamespaces.putNSPrefix(nsName, nsPrefix);
                        // If it is due for removal, rememebr it in the oldAttributes list.
                        if (removeDuplicateNSDeclarations && (prefixExists || nsName.equals(newNamespaces.getDefaultNSName())))
                            oldAttributes.addElement(attr);
                    }
                }
            }
        }

        // Remove all the duplicates on the given element.
        Enumeration e = oldAttributes.elements();
        while (e.hasMoreElements())
            element.removeAttributeNode((Attr) e.nextElement());

        // Answer the new list of namespaces for this element.
        return newNamespaces;
    }
protected static Namespaces getNamespaces(Element element, Namespaces namespaces, boolean removeDuplicateNSDeclarations) {

        // Create a container to hold the new namespace definitions.
        Namespaces newNamespaces = null;
        if (namespaces == null)
            newNamespaces = new Namespaces();
        else
            newNamespaces = new Namespaces(namespaces);

        Vector oldAttributes = new Vector();

        // For each attribute on the given element.
        NamedNodeMap nodeMap = element.getAttributes();
        for (int i = 0; i < nodeMap.getLength(); ++i) {
            Attr attr = (Attr) nodeMap.item(i);

            // Is it a name space declaration?
            String name = attr.getName();
            if (name.startsWith(XML_PREFIX)) {
                String nsName = attr.getValue();

                // Is it setting or clearing the default namespace?
                // (i.e. has no prefix part)
                if (name.length() == XML_PREFIX.length()) {
                    if (nsName.equals("")) //$NON-NLS-1$
                        newNamespaces.setDefaultNSName(null);
                    else
                        newNamespaces.setDefaultNSName(nsName);
                } else if (name.charAt(XML_PREFIX.length()) == ':') {
                    // It is a namespace declaration.
                    String nsPrefix = name.substring(XML_PREFIX.length() + 1);
                    if (nsPrefix.length() > 0 && nsName.length() > 0) {
                        // Ensure it is in the new namespaces list.
                        newNamespaces.putNSName(nsPrefix, nsName);
                        boolean prefixExists = newNamespaces.getNSPrefix(nsName) != null;
                        if (!prefixExists)
                            newNamespaces.putNSPrefix(nsName, nsPrefix);
                        // If it is due for removal, rememebr it in the oldAttributes list.
                        if (removeDuplicateNSDeclarations && (prefixExists || nsName.equals(newNamespaces.getDefaultNSName())))
                            oldAttributes.addElement(attr);
                    }
                }
            }
        }

        // Remove all the duplicates on the given element.
        Enumeration e = oldAttributes.elements();
        while (e.hasMoreElements())
            element.removeAttributeNode((Attr) e.nextElement());

        // Answer the new list of namespaces for this element.
        return newNamespaces;
    }
Returns the given element's namespace declarations. The given
namespace declarations should be the element's parent's, or
<code>null</code> if the element has no parent. If
removeDuplicateNSDeclarations is <code>true</code>, duplicate
namespace declarations are removed from the element's attributes. The
element must not be <code>null</code>.

@param element    the element whose namespace declaration is returned
@param namespaces the namespace declarations for the element's
parent's or <code>null</code> if it has no parent
@param removeDuplicateNSDeclarations a boolean indicating whether
duplicate namespace declarations should be removed
from the element's attributes
@return           the given element's namespace declarations