Example usage for org.w3c.dom Element getNamespaceURI

List of usage examples for org.w3c.dom Element getNamespaceURI

Introduction

In this page you can find the example usage for org.w3c.dom Element getNamespaceURI.

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:Main.java

private static String getLocalName(Element elem) {
    return (elem.getNamespaceURI() == null) ? elem.getTagName() : elem.getLocalName();
}

From source file:Utils.java

public static QName getElementQName(Element el) {
    return new QName(el.getNamespaceURI(), el.getLocalName());
}

From source file:Main.java

public static boolean is(Element element, QName qName) {
    final boolean equals = qName.equals(new QName(element.getNamespaceURI(), element.getTagName()));
    return equals;
}

From source file:Main.java

public static List<Element> getChildElementsNS(Element parent, String uri) {
    List<Element> ret = new ArrayList<Element>();
    NodeList childList = parent.getChildNodes();
    for (int i = 0; i < childList.getLength(); i++) {
        if (childList.item(i).getNodeType() != Node.ELEMENT_NODE)
            continue;
        Element child = (Element) childList.item(i);
        if (child.getNamespaceURI().equals(uri))
            ret.add(child);//from  w  ww .  ja  v  a 2  s .c  om
    }
    return ret;
}

From source file:Main.java

public static Element first(Element root, String namepaceUri, String localName) {
    if (root == null)
        return null;
    for (Node n1 = root.getFirstChild(); n1 != null; n1 = n1.getNextSibling()) {
        if (n1.getNodeType() != Node.ELEMENT_NODE)
            continue;
        Element e2 = Element.class.cast(n1);
        if (namepaceUri.equals(e2.getNamespaceURI()) && e2.getLocalName().equals(localName)) {
            return e2;
        }// www  .  j  a v a 2 s. co m
    }
    return null;
}

From source file:Main.java

/**
 * @param xml//from   ww w .java  2  s .  co  m
 *            The Element whose QName will be returned.
 * @return The QName of the given Element definition.
 */
public static QName getElementQName(final Element xml) {
    final String uri = xml.getNamespaceURI();
    final String prefix = xml.getPrefix();
    final String name = xml.getLocalName();

    //
    // support for DOM Level 1 - no NS concept
    //
    if (name == null)
        return new QName(xml.getNodeName());

    //
    // prefix is not required, but it CANNOT be null
    //
    if (prefix != null && prefix.length() > 0)
        return new QName(uri, name, prefix);

    return new QName(uri, name);
}

From source file:Main.java

public static Element[] filterChildElements(Element parent, String ns, String lname) {

    List<Element> elems = new ArrayList<Element>();
    NodeList nlst = parent.getChildNodes();
    for (int i = 0, nlen = nlst.getLength(); i < nlen; i++) {
        Node n = nlst.item(i);/*  w w  w.j a  v a2  s .  c o m*/
        if (n instanceof Element) {
            Element e = (Element) n;
            if ((ns == null || ns.equals(e.getNamespaceURI()))
                    && (lname == null || lname.equals(e.getLocalName()))) {
                elems.add(e);
            }
        }
    }
    return elems.toArray(new Element[elems.size()]);
}

From source file:Utils.java

/**
 * Return child elements with specified name.
 * /*from ww  w  .  j  a v  a 2s  .c om*/
 * @param parent
 * @param ns
 * @param localName
 * @return
 */
public static List<Element> getChildrenWithName(Element parent, String ns, String localName) {
    List<Element> r = new ArrayList<Element>();
    for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n instanceof Element) {
            Element e = (Element) n;
            String eNs = (e.getNamespaceURI() == null) ? "" : e.getNamespaceURI();
            if (ns.equals(eNs) && localName.equals(e.getLocalName())) {
                r.add(e);
            }
        }
    }
    return r;
}

From source file:Utils.java

/**
 * Return the first element child with the specified qualified name.
 * /*from  w w  w. j  a  v a 2s .c  o m*/
 * @param parent
 * @param ns
 * @param lp
 * @return
 */
public static Element getFirstChildWithName(Element parent, String ns, String lp) {
    for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n instanceof Element) {
            Element e = (Element) n;
            String ens = (e.getNamespaceURI() == null) ? "" : e.getNamespaceURI();
            if (ns.equals(ens) && lp.equals(e.getLocalName())) {
                return e;
            }
        }
    }
    return null;
}

From source file:Main.java

/**
 * Given an element, returns all its direct child elements that have the
 * specified namespace and name.  Use null to indicate the empty namespace.
 *///from   w w  w .  j  av  a  2s.  c o m
public static List<Element> getElementsNS(Element element, String namespaceURI, String localName) {
    List<Element> elements = new ArrayList<>();
    for (Element candidate : getElements(element)) {
        if (namespaceURI.equals(candidate.getNamespaceURI()) && localName.equals(candidate.getLocalName())) {
            elements.add(candidate);
        }
    }
    return elements;
}