Java XML Attribute Get getAttributeIgnoreCase(Element element, String attributeName)

Here you can find the source of getAttributeIgnoreCase(Element element, String attributeName)

Description

Gets the DOM attribute of element with the given name.

License

Open Source License

Parameter

Parameter Description
element the source element
attributeName the attribute name

Return

the XML attribute if any, null otherwise

Declaration

public static Attr getAttributeIgnoreCase(Element element, String attributeName) 

Method Source Code

//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;
    }
}

Related

  1. getAttributeContent(Node item, String attributeName)
  2. getAttributeEnum(Node node, String attributeName, Class enumClass)
  3. getAttributeFloatValue(String attribute, NamedNodeMap namedNodeMap)
  4. getAttributeFromClosestAncestorOfAnyKind(Node node, String attributeName)
  5. getAttributeIfExists(Node node, String name)
  6. getAttributeIgnoreCase(Element element, String string)
  7. getAttributeIntArray(final Node node, final String attribname)
  8. getAttributeInteger(String filename, Element parent, String name)
  9. getAttributeInteger(String filename, Element parent, String name)