/***
* 把一个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;
}
本文详细阐述了如何将XML字符串转换为XML文档对象的过程,包括XML字符串的解析与XML文档对象的创建。

被折叠的 条评论
为什么被折叠?



