Here you can find the source of getAttribute(Element el, QName attributeName)
Parameter | Description |
---|---|
el | owner element. |
attributeName | QName of the attribute node to be searched. |
static public Attr getAttribute(Element el, QName attributeName)
//package com.java2s; /******************************************************************************* * Copyright (c) 2002-2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w .j av a 2s . c o m * IBM - Initial API and implementation *******************************************************************************/ import javax.xml.namespace.QName; import org.w3c.dom.Attr; import org.w3c.dom.Element; public class Main { /** * The method returns attribute node by the given qname. * * @param el owner element. * @param attributeName QName of the attribute node to be searched. * @return attribute node by the given qname. */ static public Attr getAttribute(Element el, QName attributeName) { if (el == null) throw new IllegalArgumentException("Element can not be NULL"); if (attributeName == null) throw new IllegalArgumentException("Attribute name can not be NULL"); String nsURI = attributeName.getNamespaceURI(); String localPart = attributeName.getLocalPart(); if (localPart == null) throw new IllegalArgumentException("Local part of the attribute name can not be NULL"); Attr a = el.getAttributeNodeNS(nsURI, localPart); if (a == null) // try to get with null namespace a = el.getAttributeNodeNS(null, localPart); return a; } }