我有一个如下的 XML(有 100 行):
<root>
<data v="1.0">
<cellimage counter="0" cash_filename="C:\Temp\_TempFolder\39d437f08cc302876a70a0f91b137991_h.jpg" width="94" height="141" />
<cellimage counter="1" cash_filename="C:\Temp\_TempFolder\39d437f08cc302876a70a0f91b137991_h.jpg" width="94" height="141" />
</data>
</root>
谁能告诉我如何循环遍历它并从 JSP 中的上述 XML 文件中提取“counter”和“cash_filename”等属性。
到目前为止,我有以下代码:
<%
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse("http://localhost:8080/data.xml");
NodeList nl = doc.getElementsByTagName("cellimage");
for (int i = 0; i < nl.getLength(); i++) {
//Not sure what to do here!
}
%>