Java 怎么获取指定XML属性的值作为颜色

2019年7月21日19:51:31Java 怎么获取指定XML属性的值作为颜色已关闭评论 446 891字阅读2分58秒

1.简介

Java 怎么获取指定XML属性的值作为颜色?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap;

public class Main {
    
     
    public static int getAttributeValueAsColor(NamedNodeMap attribs,
            String attributeName, int defValue) throws DOMException {
        String v = getAttributeValue(attribs, attributeName);
        int result = defValue;

        if (v != null) {
            try {
                result = Integer.parseInt(v, 16);
            } catch (NumberFormatException ex) {
            }
        }
        return result;
    }

    
    public static String getAttributeValue(NamedNodeMap attribs,
            String attributeName) throws DOMException {
        String value = null;
        if (attribs.getNamedItem(attributeName) != null) {
            value = attribs.getNamedItem(attributeName).getNodeValue();
        }
        return value;
    }

    
    public static String getAttributeValue(NamedNodeMap attribs,
            String attributeName, String defValue) throws DOMException {
        if (attribs.getNamedItem(attributeName) != null) {
            return attribs.getNamedItem(attributeName).getNodeValue();
        } else {
            return defValue;
        }
    }
}

 
继续阅读
编程十万个怎么办