Here you can find the source of getAttributeIgnoreCase(Element element, String attributeName)
element
with the given name.
Parameter | Description |
---|---|
element | the source element |
attributeName | the attribute name |
public static Attr getAttributeIgnoreCase(Element element, String attributeName)
//package com.java2s; /*/*ww w . j a va2s .c o m*/ * ? Copyright IBM Corp. 2012 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing * permissions and limitations under the License. */ import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; public class Main { /** * Gets the DOM attribute of <code>element</code> with the given name. * It returns the first attribute that matches the name, regardless the case. * This is particularly useful when dealing with an HTML DOM, as HTML is not * case sensitive. * @param element the source element * @param attributeName the attribute name * @return the XML attribute if any, null otherwise */ public static Attr getAttributeIgnoreCase(Element element, String attributeName) { NamedNodeMap nm = element.getAttributes(); for (int i = 0; i < nm.getLength(); i++) { Attr a = (Attr) nm.item(i); if (a.getName().equalsIgnoreCase(attributeName)) { return a; } } return null; } }