运行以下代码时遇到问题
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("C:\\Users\\V\\Documents\\douleia\\temp\\dokimi.xml");
try {
Document document = (Document) builder.build(xmlFile);
Element rootNode = document.getRootElement();
List list = rootNode.getChildren("safety_application");
for (int i = 0; i < list.size(); i++) {
Element element = (Element) list.get(i);
System.out.println("number :" + element.getAttributeValue("id"));
System.out.println("element : " + element.getChildText("element"));
System.out.println("File_name : " + element.getChildText("name"));
}
}
catch (Exception e) {
e.printStackTrace();
}
我没有收到任何错误,但它没有打印任何内容。这意味着程序应该打印number: 1
element: element
File_name: AND
我得到这样的输出[]
我的 XML 文件有这种形式
<safety_application>
<element id="1">
<name>AND</name>
</element>
<element id="2">
<name>OR</name>
</element>
</safety_application>