我有一个包含XML数据的字符串,我想将其转换为XML文档对象。我该怎么做?
假设theString保存了XML代码:
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.parse(new InputSource(new StringReader(theString)));
更多信息在这里
docBuilder.parse(theString);
期望传入 URI,而不是字符串本身。 - Filippo Mazza