DOM4J

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);

        }
    }
 

你可能感兴趣的:(java,dom4j)