设置xml节点属性值
/**
* 设置xml节点属性值
* @param dom
* @param tagName
* @param attributeName
* @param value
* @return
*/
public static boolean setAttributeValueFromDom(Document dom,String tagName,String attributeName,String value)
{
boolean result = false;
if (dom != null && tagName != null && !tagName.trim().equals("")
&& attributeName != null && !attributeName.trim().equals(""))
{
NodeList nodeList = null;
Node node = null;
nodeList = dom.getElementsByTagName(tagName.trim());
if (nodeList !=null && nodeList.getLength() > 0)
{
/**
* xml中可能有多个tagName定义的Node,取第一个
*/
node = nodeList.item(0);
if (node != null)
{
((Element)node).setAttribute(attributeName, value);
result = true;
}
}
}
return result;
}