微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

把一个XML字符串转换为一个XML文档对象

/***
* 把一个XML字符串转换一个XML文档对象
* @param returnXML : XML字符串
* @return Document xml文档对象
* @throws Exception
*/
private org.w3c.dom.Document getDocument(String returnXML) throws BOException
{
org.w3c.dom.Document doc = null;
if (returnXML != null && returnXML.length() > 0)
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = null;
try
{
db = dbf.newDocumentBuilder();
}
catch (ParserConfigurationException pce)
{
pce.printstacktrace();
}
try
{
StringReader rd = new StringReader(returnXML);
InputSource in = new InputSource(rd);
doc = db.parse(in);

} catch (IOException ioe) { ioe.printstacktrace(); } catch (SAXException saxe) { saxe.printstacktrace(); } } return doc; }

原文地址:https://www.jb51.cc/xml/300457.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。