xufenglei
2018-08-24 158a0ab4db8c34363e5460dbec287c8af1f0f277
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.moral.common.util;
 
import java.io.File;
import java.util.ArrayList;
import java.util.List;
 
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.stereotype.Component;
 
@Component
@SuppressWarnings("unchecked")
public class Dom4jUtils {
 
    private static ArrayList<Element> elements;
    
    public static List<Element> readDocument() {
        try {
            Document document = new SAXReader().read(new File("src/main/resources/system/city.xml"));
            Element rootElement = document.getRootElement();
            elements = (ArrayList<Element>) rootElement.elements();
            System.out.println(elements.size());
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return elements;
    }
    
    public static List<Element> getDocuments() {
        return elements;
    }
}