/**
* 获取指定的节点key
* @param xmlString
* @param elementKey
* @return
*/
public static String parseXMLStringTOGetElement(String xmlString,String elementKey){
DocumentBuilder builder = XMLHelper.getDocumentBuilder();
try {
Document document = builder.parse(new InputSource(new StringReader(xmlString)));
NodeList nodeList = document.getElementsByTagName(elementKey);
if(nodeList!=null && nodeList.getLength()>0){
return nodeList.item(0).getFirstChild().getNodeValue();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/**
* 获取DocumentBuilder对象
* @return
*/
public static DocumentBuilder getDocumentBuilder(){
try {
return DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
return null;
}
}
DocumentBuilder 解析出指定节点XMLString数据
最新推荐文章于 2024-06-29 12:06:41 发布