Example usage for org.w3c.dom Node getLocalName

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

Introduction

In this page you can find the example usage for org.w3c.dom Node 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 List<Element> find(Node root, String nsUri, String localName, boolean recursive) {
    List<Element> result = new ArrayList<Element>();
    NodeList nl = root.getChildNodes();
    if (nl != null) {
        int len = nl.getLength();
        for (int i = 0; i < len; i++) {
            Node child = nl.item(i);
            if (child instanceof Element) {
                String childUri = child.getNamespaceURI();
                String childLocalName = child.getLocalName();
                if (("*".equals(nsUri) || nsUri == null && childUri == null || nsUri.equals(childUri))
                        && localName.equals(childLocalName)) {
                    result.add((Element) child);
                } else if (recursive) {
                    result.addAll(find(child, nsUri, localName, recursive));
                }/*from w  w  w .  j  av a2  s  .  c om*/
            }
        }
    }
    return result;
}

From source file:com.dinstone.jrpc.spring.EndpointBeanDefinitionParser.java

private static boolean nodeMatch(Node node, String desiredName) {
    return (desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName()));
}

From source file:Main.java

/**
 * Namespace-aware equals comparison. Returns <code>true</code> if either
 * {@link Node#getLocalName} or {@link Node#getNodeName} equals <code>desiredName</code>,
 * otherwise returns <code>false</code>.
 *//*from ww w . j  a v  a 2s  .c o m*/
public static boolean nodeNameEquals(Node node, String desiredName) {
    assert node != null : "Node must not be null";
    assert desiredName != null : "Desired getName must not be null";
    return desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName());
}

From source file:Main.java

@Nullable
public static String getElementName(@Nullable final Node aNode) {
    if (aNode instanceof Document)
        return getElementName(((Document) aNode).getDocumentElement());
    if (aNode instanceof Element) {
        String ret = aNode.getLocalName();
        if (ret == null)
            ret = ((Element) aNode).getTagName();
        return ret;
    }/*w  ww . j a v a  2s  . c om*/
    return null;
}

From source file:Main.java

static public boolean isA(Node e, String ns, String localname) {
    if (e == null)
        return false;
    //if(e.getNodeType()!=Node.ELEMENT_NODE) return false;
    return ns.equals(e.getNamespaceURI()) && e.getLocalName().equals(localname);
}

From source file:Main.java

private static Set<String> getTree(Node doc) {
    final Set<String> set = new TreeSet<String>();
    if (doc == null)
        return set;

    String path = new String();
    if (doc.getPrefix() != null && doc.getLocalName() != null) {
        path = new String(doc.getPrefix() + ":" + doc.getLocalName());
        set.add(path);/*from  w w  w  .ja va2 s  .c o  m*/
    }

    final NamedNodeMap attributes = doc.getAttributes();
    for (int i = 0; attributes != null && i < attributes.getLength(); i++) {
        final Node attribute = attributes.item(i);
        String name = attribute.getLocalName();
        if (attribute.getPrefix() != null)
            name = attribute.getPrefix() + ":" + name;
        set.add(path + "/@" + name);
    }

    final NodeList nodes = doc.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        final Node node = nodes.item(i);
        if (node instanceof Element) {
            final Set<String> children = getTree(node);
            for (final String child : children) {
                set.add(path + "/" + child);
            }
        }
    }
    return set;
}

From source file:Main.java

/**
 * @param sibling//from w w  w  .  j a va  2s  .  c  om
 * @param uri
 * @param nodeName
 * @param number
 * @return nodes with the constrain
 */
public static Element selectNode(Node sibling, String uri, String nodeName, int number) {
    while (sibling != null) {
        if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
                && sibling.getLocalName().equals(nodeName)) {
            if (number == 0) {
                return (Element) sibling;
            }
            number--;
        }
        sibling = sibling.getNextSibling();
    }
    return null;
}

From source file:Main.java

/**
 * Builds an XPath string referencing the given node relative to it's parent.
 * //from   w  w  w .  java 2  s .  c o m
 * @param node
 * @param context namespace context used to determine correct namespace prefixes, see
 *            {@link SignavioNamespaceContext}
 * @return a relative XPath string or null (if no node given)
 */
private static String getNodeString(Node node, NamespaceContext context) {
    if (node == null) {
        return null;
    }

    // get qualified name
    String nodeName = node.getLocalName();
    if (nodeName == null)
        nodeName = node.getNodeName();

    if (node.getNamespaceURI() != null) {
        String prefix = context.getPrefix(node.getNamespaceURI());
        nodeName = prefix + ":" + node.getLocalName();
    }

    if (node instanceof Attr) {
        return "@" + nodeName;
    } else if (node instanceof Text) {
        nodeName = "text()";
    }

    // determine position
    Node current = node;
    while (current.getPreviousSibling() != null) {
        current = current.getPreviousSibling();
    }
    int position = 1;

    while (current != node) {
        if (current.getNodeName().equals(node.getNodeName()))
            position++;
        current = current.getNextSibling();
    }

    return nodeName + "[" + position + "]";
}

From source file:com.weibo.wesync.notify.xml.DomUtils.java

/** Matches the given node's name and local name against the given desired name. */
private static boolean nodeNameMatch(Node node, String desiredName) {
    return (desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName()));
}

From source file:Main.java

/**
 * @param sibling//from   w  w  w  .j  a v  a 2  s  .c  o m
 * @param uri
 * @param nodeName
 * @return nodes with the constrain
 */
public static Element[] selectNodes(Node sibling, String uri, String nodeName) {
    List<Element> list = new ArrayList<Element>();
    while (sibling != null) {
        if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
                && sibling.getLocalName().equals(nodeName)) {
            list.add((Element) sibling);
        }
        sibling = sibling.getNextSibling();
    }
    return list.toArray(new Element[list.size()]);
}