lizijie
2021-11-29 d8310f6bc609440fa352c0e5a9436c7c78caa287
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
36
37
package com.moral.util;
 
import java.io.File;
import java.net.URL;
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 {
            URL url = com.moral.util.Dom4jUtils.class.getClassLoader().getResource("system" + File.separator + "city.xml");
            Document document = new SAXReader().read(url);
            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;
    }
}