Java的XML解析器似乎认为我的XML文档在根元素之后没有很好地形成.但是我已经用几种工具对它进行了验证,他们都不同意.这可能是我的代码中的错误,而不是文档本身.我非常感谢你们能给我的任何帮助.
这是我的Java方法:
private void loadFromXMLFile(File f) throws ParserConfigurationException, IOException, SAXException {
File file = f;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
Document doc = null;
db = dbf.newDocumentBuilder();
doc = db.parse(file);
doc.getDocumentElement().normalize();
String desc = "";
String due = "";
String comment = "";
NodeList tasksList = doc.getElementsByTagName("task");
for (int i = 0; i tasksList.getLength(); i++) {
NodeList attributes = tasksList.item(i).getChildNodes();
for (int j = 0; i < attributes.getLength(); j++) {
Node attribute = attributes.item(i);
if (attribute.getNodeName() == "description") { …Run Code Online (Sandbox Code Playgroud)