/**
* 根据tagName从xml中取得取得相应Node值 格式:getNodeValueFromDom(dom,"消息/消息内容/学号")
*
* @param dom
* @param tagName
* @return
*/
public static String getNodeValueFromDom(Document dom, String tagName) {
String result = "";
try {
if (dom != null && tagName != null && !tagName.trim().equals("")) {
NodeList nodeList = null;
Node node = null;
nodeList = XPathAPI.selectNodeList(dom, tagName.trim());// dom.getElementsByTagName(tagName.trim());
if (nodeList != null && nodeList.getLength() > 0) {
/**
* xml中可能有多个tagName定义的Node,取第一个
*/
node = nodeList.item(0);
if (node != null) {
node = node.getFirstChild();
if (node != null)
result = node.getNodeValue();
result = result == null ? "" : result.trim();
}
}
}
} catch (Exception e) {
System.out.println(" getNodeValueFromDom 出错 = " + e.toString());
e.printStackTrace();
}
return result;
}