//删除没有子节点的节点
private String validXML(String strNBCNewAlertNotification) throws Exception{
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
dbFactory.setValidating(true);
DocumentBuilder dbBuilder = dbFactory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(strNBCNewAlertNotification));
Document doc = dbBuilder.parse(is);
NodeList domainValueList=doc.getElementsByTagNameNS("*", "actionObject");
if(null ==domainValueList || domainValueList.getLength() == 0){
NodeList domainValueList2=doc.getElementsByTagNameNS("*", "actionObjectList");
Node node = domainValueList2.item(0);
//这个是重点,自己不能删除自己,找到 父node.getParentNode() 再删除 子.removeChild(node);
node.getParentNode().removeChild(node);
//save xml
// XML
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
//拿到删除之后的xml
t.transform(new DOMSource(doc), new StreamResult(bos));
strNBCNewAlertNotification = bos.toString();
}
return strNBCNewAlertNotification;
}