Android XML Attribute Get getNodeAttributeOrFail( Node node, String name, T e)

Here you can find the source of getNodeAttributeOrFail( Node node, String name, T e)

Description

Retrieves the value for a xml Node attribute or fails if not found.

License

Open Source License

Parameter

Parameter Description
T the exception type to throw
node The Node to fetch the value from.
name The attribute name.
e an Exception instance

Exception

Parameter Description
T an exception

Return

the attribute value

Declaration

public static <T extends Exception> String getNodeAttributeOrFail(
        Node node, String name, T e) throws T 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    /** Retrieves the value for a xml Node attribute or fails if not found.
     * //from  w ww  .  j a  v a2s  .c  o m
     * @param <T> the exception type to throw
     * @param node The Node to fetch the value from.
     * @param name The attribute name.
     * @param e an Exception instance
     * @return the attribute value
     * @throws T */
    public static <T extends Exception> String getNodeAttributeOrFail(
            Node node, String name, T e) throws T {
        NamedNodeMap attributes = node.getAttributes();
        Node valueNode = attributes.getNamedItem(name);
        if (valueNode == null)
            throw e;
        return valueNode.getNodeValue();
    }
}

Related

  1. getAttribute(String key, Attributes attributes, Map tagCache)
  2. getAttributesValue(Attributes attrs, String name)
  3. getXmlAttribute(Context context, XmlResourceParser xml, String name)
  4. getNodeAttributeOrDefault(Node node, String name, String defaultValue)
  5. getNodeAttributeOrFail( Node node, String name, ExceptionType e)