New file |
| | |
| | | package com.moral.common.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 = 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;
|
| | | }
|
| | | }
|