欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

        }
    }
 
相关标签: java DOM4J