LocList.xml地址
链接:https://pan.baidu.com/s/19_HZNuFWXFbiuLzOLiCUPw
提取码:ejf1
复制这段内容后打开百度网盘手机App,操作更方便哦
解析xml
@Component
public class AddressUtil {
//1.通过路径
private String filePath = ClassUtils.getDefaultClassLoader().getResource("").getPath();
private SAXReader reader;
private Document document;
private static Element rootElement;
private void getRootElement() {
try {
//LocList.xml 放在了resources下
//1.通过路径
//document = reader.read(new File(filePath + "LocList.xml"));
//2.通过流的方式
ClassPathResource classPathResource = new ClassPathResource("LocList.xml");
InputStream inputStream = classPathResource.getInputStream();
reader = new SAXReader();
document = reader.read(inputStream);
//根节点
rootElement = document.getRootElement();
} catch (DocumentException | IOException e) {
e.printStackTrace();
}
}
public String getlxxzStr(String countryCode, String provinceCode, String cityCode, String areaCode) {
getRootElement();
StringBuffer buf = new StringBuffer();
String provinceName;
String cityName;
String areaName;
//根节点
if (!ObjectUtils.isEmpty(countryCode)) {
Iterator<Element> rootEle = rootElement.elementIterator();//中国
if (!ObjectUtils.isEmpty(provinceCode)) {