Java XML Attribute Get getAttributeValueNS(Element element, String namespace, String attrName)

Here you can find the source of getAttributeValueNS(Element element, String namespace, String attrName)

Description

Get attribute value.

License

Open Source License

Parameter

Parameter Description
element an Element object.
namespace a namespace.
attrName a name of an attribute

Return

the attribute value.

Declaration

public static String getAttributeValueNS(Element element, String namespace, String attrName) 

Method Source Code

//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:/*  ww  w. j  av a 2s.co  m*/
 *   IBM - Initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Attr;

import org.w3c.dom.Element;

public class Main {
    /**
     * Get attribute value.
     * 
     * @param element an Element object.
     * @param namespace a namespace.
     * @param attrName a name of an attribute
     * @return the attribute value.
     */
    public static String getAttributeValueNS(Element element, String namespace, String attrName) {
        String attrValue = null;
        Attr attr = null;

        // Get the attribute using its name
        if ((attr = element.getAttributeNodeNS(namespace, attrName)) != null) {
            attrValue = attr.getValue().trim();
        }

        // Return attribute value
        return attrValue;
    }
}

Related

  1. getAttributeValueByName(Node node, String name)
  2. getAttributeValueByName(Node node, String name)
  3. getAttributeValueEmptyNull(Element e, String attributeName)
  4. getAttributeValueIgnoreCase(Element element, String attributeName)
  5. getAttributeValueNS(@Nonnull final Element aElement, @Nullable final String sNamespaceURI, @Nonnull final String sAttrName, @Nullable final String sDefault)
  6. getAttributeValueOrNull(NamedNodeMap attributes, String attributeName)
  7. getAttributeValuePair(Node node)
  8. getAttributeValues(Element el)
  9. getAttributeValues(Node node, String nodeName, String attrName)