Here you can find the source of getAttributeValueIgnoreCase(Element element, String attributeName)
element
with the given name It returns the first attribute value that matches the name, regardless the case.
Parameter | Description |
---|---|
element | the source element |
attributeName | the attribute name |
public static String getAttributeValueIgnoreCase(Element element, String attributeName)
//package com.java2s; /*//from ww w . j a v a 2s . c om * ? 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 value of DOM attribute of <code>element</code> with the given name * It returns the first attribute value 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 String getAttributeValueIgnoreCase(Element element, String attributeName) { Attr a = getAttributeIgnoreCase(element, attributeName); if (a != null) { a.getValue(); } return null; } /** * 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; } }