Here you can find the source of isElementNamed(Element e, String ns, String localName)
Parameter | Description |
---|---|
e | An element to compare against |
ns | An XML namespace to compare |
localName | A local name to compare |
public static boolean isElementNamed(Element e, String ns, String localName)
//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); } }