Java XML Element Check isElementNamed(Element e, String ns, String localName)

Here you can find the source of isElementNamed(Element e, String ns, String localName)

Description

Shortcut for checking a DOM element node's namespace and local name

License

Open Source License

Parameter

Parameter Description
e An element to compare against
ns An XML namespace to compare
localName A local name to compare

Return

true iff the element's local name and namespace match the parameters

Declaration

public static boolean isElementNamed(Element e, String ns, String localName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Element;

public class Main {
    /**//  w  w w .  ja va  2  s  . c o  m
     * Shortcut for checking a DOM element node's namespace and local name
     * 
     * @param e
     *            An element to compare against
     * @param ns
     *            An XML namespace to compare
     * @param localName
     *            A local name to compare
     * @return true iff the element's local name and namespace match the
     *         parameters
     */
    public static boolean isElementNamed(Element e, String ns, String localName) {
        return (e != null && safeCompare(ns, e.getNamespaceURI()) && safeCompare(localName, e.getLocalName()));
    }

    /**
     * Compares two strings for equality, allowing for nulls
     * 
     * @param s1
     *            The first operand
     * @param s2
     *            The second operand
     * @return true iff both are null or both are non-null and the same strng
     *         value
     */
    public static boolean safeCompare(String s1, String s2) {
        if (s1 == null || s2 == null)
            return s1 == s2;
        else
            return s1.equals(s2);
    }
}

Related

  1. isAppearanceTag(Element e)
  2. isAsyncEventQueue(Element element)
  3. isComputedGoal(final Element element)
  4. isElement(XMLStreamReader xmlRdr, int eventType, String tagName)
  5. isElementExistsByTagName(final Element element, final String tagName)
  6. isEmpty(final Element el)
  7. isEmptyElement(Element el)
  8. isExtension(Element element)
  9. isGateway(Element element)