DOM4J
程序员文章站
2022-05-29 11:46:17
...
public static void main(String[] args){
String templateFileName = xxx.class.getResource("/config.xml").getFile();
File inputXml = new File(templateFileName);
SAXReader saxReader = new SAXReader();
Document document = null;
try {
document = saxReader.read(inputXml);
} catch (DocumentException e) {
e.printStackTrace();
}
Element root = document.getRootElement();
Element source = root.element("source");
List property =source.elements();
for(Element element :(List<Element>) property){
int mapIndex = Integer.parseInt(element.attributeValue("mapIndex"));
String cellName = element.attributeValue("name");
System.out.println(mapIndex +" "+cellName);
}
}