就我而言,输入' xml2.xml3(4);'在其他类中。结果显示在控制台中。
结果可以显示在文本字段中吗?
public class xml2 {
public static void xml3(int index) {
try {
File fXmlFile = new File("AST10106_ProjectSampleData.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("record");
Node nNode = nList.item(index);
Element eElement = (Element) nNode;
System.out.println("Record : " + eElement.getAttribute("record"));
System.out.println("Brand : " + eElement.getElementsByTagName("Brand").item(0).getTextContent());
} catch (Exception e) {
e.printStackTrace();
}
}
}