Example usage for org.w3c.dom Element getLocalName

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

Introduction

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

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:Main.java

private static void findDescendantsByName(Element e, String name, List<Element> list) {
    if (e.getLocalName().equals(name))
        list.add(e);//  w ww  .j  ava  2  s. co  m
    for (Element e1 : getChildElements(e))
        findDescendantsByName(e1, name, list);
}

From source file:Main.java

public static void getNamedChildren(Element e, String name, List<Element> set) {
    Element c = getFirstChild(e);
    while (c != null) {
        if (name.equals(c.getLocalName()) || name.equals(c.getNodeName()))
            set.add(c);/*from   w  ww .ja  v  a2 s  .  co  m*/
        c = getNextSibling(c);
    }
}

From source file:Main.java

public static void getNamedChildrenWithWildcard(Element focus, String name, List<Element> children) {
    Element c = getFirstChild(focus);
    while (c != null) {
        String n = c.getLocalName() != null ? c.getLocalName() : c.getNodeName();
        if (name.equals(n) || (name.endsWith("[x]") && n.startsWith(name.substring(0, name.length() - 3))))
            children.add(c);/*  w w  w .j a  va2  s  .  c o m*/
        c = getNextSibling(c);
    }

}

From source file:Main.java

private static Element findElementinChilds(Node node, String uri, String nodeName) {

    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element childElement = (Element) child;

            if (nodeName.equals(childElement.getLocalName()) && uri.equals(childElement.getNamespaceURI())) {
                return (Element) childElement;
            }//w  ww  .j  a  v  a 2s.  c o m
        }

        Element located = findElementinChilds(child, uri, nodeName);
        if (located != null) {
            return located;
        }
    }

    return null;
}

From source file:Main.java

private static boolean match(final Node node, final String namespace, final String localname) {
    if (node instanceof Element) {
        Element element = (Element) node;
        if (element.getLocalName().equals(localname)) {
            if (namespace == null || namespace.equals(element.getNamespaceURI())) {
                return true;
            }/*from ww w .  java  2s.  c  om*/
        }
    }

    return false;
}

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;
        }/*from  w ww .  j a  v  a  2 s .  co  m*/
    }
    return null;
}

From source file:Main.java

/**
 * Find element.//from   w  ww  . j  a v a2s .  c o  m
 * 
 * @param topElm
 *        the top elm
 * @param localName
 *        the local name
 * @param namespace
 *        the namespace
 * @return the element
 */
public static Element findElement(Element topElm, String localName, String namespace) {
    Stack<Element> stack = new Stack<Element>();
    stack.push(topElm);
    while (!stack.isEmpty()) {
        Element curElm = stack.pop();
        if ((curElm.getLocalName().equals(localName))
                && (namespacesAreSame(curElm.getNamespaceURI(), namespace))) {
            return curElm;
        }
        NodeList childNodes = curElm.getChildNodes();
        for (int i = 0, ll = childNodes.getLength(); i < ll; i++) {
            Node item = childNodes.item(i);
            if (item.getNodeType() == Node.ELEMENT_NODE) {
                stack.push((Element) item);
            }
        }
    }
    return null;
}

From source file:Main.java

/**
 * Get the name from the supplied element.
 * Returns the {@link Node#getLocalName() localName} of the element
 * if set (namespaced element), otherwise the
 * element's {@link Element#getTagName() tagName} is returned.
 * @param element The element.//w  w  w.  j av  a2  s  .  c  om
 * @return The element name.
 */
public static String getName(Element element) {
    String name = element.getLocalName();
    if (name != null) {
        return name;
    } else {
        return element.getTagName();
    }
}

From source file:Main.java

public static String errorMessageAttribute(Element element, String attributeName, String attributeValue,
        String message) {//from   w w w. ja va 2  s.  co  m
    return "attribute <" + element.getLocalName() + " " + attributeName + "=\"" + attributeValue + "\" "
            + message;
}

From source file:Main.java

public static List<Element> elements(Element root, String namepaceUri, String localName) {
    List<Element> L = new ArrayList<Element>();
    if (root == null)
        return L;
    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)) {
            L.add(e2);/*from  ww w.  j a va 2  s . c o  m*/
        }
    }
    return L;
}