string 转成 dom 方法返回空值null
public static void main(String args[]) {
String sr = "<?xml version=\"1.0\" ?><root><C_DATA_CHANGED><IMLC_LCISSUE><C_LC_NO><OLD></OLD><NEW>A002</NEW></C_LC_NO><D_ISSU_DATE><OLD></OLD><NEW>2002-08-23</NEW></D_ISSU_DATE><C_CHARGE_WITH><OLD></OLD><NEW>BENE</NEW></C_CHARGE_WITH></IMLC_LCISSUE></C_DATA_CHANGED></root>";
Document doc = strToDom(sr);
System.out.println(doc);
}
public static Document strToDom(String str){
StringReader sr = new StringReader(str);
InputSource is = new InputSource(sr);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
Document doc = null;
try {
builder = factory.newDocumentBuilder();
doc = builder.parse(is);
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
MessageDataService.saveException(e.toString());
} catch (SAXException e) {
// TODO Auto-generated catch block
MessageDataService.saveException(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
MessageDataService.saveException(e.toString());
}
return doc;
}