ClassPathResource classPathResource = new ClassPathResource("xml/DMForms.xml");
InputStream inputStream = classPathResource.getInputStream();
用SAX读取流
SAXReader reader = new SAXReader();
Document document = reader.read(inputStream);
Element rootElement = document.getRootElement();
QName Field = new QName("OfficeFile");
List<Element> elementList = rootElement.elements(Field);
List<OfficeFile> officeFiles = new ArrayList<>();
for (int i = 0; i < elementList.size(); i++) {
OfficeFile officeFile = new OfficeFile();
Element e = elementList.get(i);
if ("字符串".equalsIgnoreCase((e.attribute("dataModel").getText()))) {
officeFile.setDataModel(e.attribute("dataModel").getText());
officeFile.setFileId(e.attribute("fileID").getText());
officeFile.setFileName(e.attribute("fileName").getText());
officeFile.setFileSortType(StringUtils.isEmpty(e.attribute("fileSortType"))?null:e.attribute("fileSortType").getText());
officeFile.setRootDepartId(e.attribute("rootDepartId").getText());
officeFile.setFileType(e.attribute("fileType").getText());
officeFiles.add(officeFile);
}
} catch (Exception e) {
throw new BizException(BizErrorCodeEnum.LOAD_XML_ERROR, BizErrorCodeEnum.LOAD_XML_ERROR.getDescription());
}