<context>
<version id="1.0">
<file name="a.class" path="d:/workspace"></file>
<file name="b.class" path="d:/workspace"></file>
</version>
</context>
我想得到id的值,与子元素name与path的值,请问如何做,尝试过用jdom,可不知如何做,请高手帮忙,急............
<version id="1.0">
<file name="a.class" path="d:/workspace"></file>
<file name="b.class" path="d:/workspace"></file>
</version>
</context>
我想得到id的值,与子元素name与path的值,请问如何做,尝试过用jdom,可不知如何做,请高手帮忙,急............
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Document xmlDoc = null;
try {
xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(new File("abc.xml"));
} catch (Exception ex) {
System.out.println("解析XML异常...");
ex.printStackTrace();
}
Node node=xmlDoc.getElementsByTagName("version").item(0);
String version=node.getAttributes().item(0).getNodeValue();
System.out.println("version="+(version==null?"":version));
NodeList list=xmlDoc.getElementsByTagName("file");
String info[][]=new String[list.getLength()][2];
for(int i=0;i<list.getLength();i++)
{
Element link=(Element) list.item(i);
info[i][0]=link.getAttribute("name");
info[i][1]=link.getAttribute("path");
System.out.println("name="+info[i][0]+",path="+info[i][1]);
}
}}