Java XML Element Get getElementNamespaces(Element element, Set namespaces)

Here you can find the source of getElementNamespaces(Element element, Set namespaces)

Description

Gets the namespaces declared on the element and adds them to the specified set.

License

Common Public License

Parameter

Parameter Description
element The element to examine.
namespaces A set to which new namespace URIs will be added.

Declaration

public static void getElementNamespaces(Element element, Set<String> namespaces) 

Method Source Code

//package com.java2s;
//License from project: Common Public License 

import java.util.Set;

import org.w3c.dom.Attr;

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

public class Main {
    /**/*from  w w  w .  j av a  2  s .  c o  m*/
     * Gets the namespaces declared on the element and adds them to the specified set.
     * @param element The element to examine.
     * @param namespaces A set to which new namespace URIs will be added.
     */
    public static void getElementNamespaces(Element element, Set<String> namespaces) {
        NamedNodeMap atts = element.getAttributes();
        for (int i = 0; i < atts.getLength(); i++) {
            Attr att = (Attr) (atts.item(i));
            String prefix = att.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                String nsURI = att.getValue();
                namespaces.add(nsURI);
            } else {
                if (att.getName().equals("xmlns")) {
                    namespaces.add(att.getValue());
                }
            }
        }
    }
}

Related

  1. getElementName(Element element)
  2. getElementName(Element element)
  3. getElementName(Field field)
  4. getElementName(Object obj)
  5. getElementNameSansNamespace(Element element)
  6. getElementNamespaceURI(Element element)
  7. getElementNS(Element el, String nsuri, String name)
  8. getElementNS(Element elem, String namespaceUri, String localName)
  9. getElementNS(Element root, Set nsUris, String wantedLocalName)