/**
* @author lyl
* @crete 2021/7/28 16:53
* @description 预归档XML文件数据封装工具类
*/
@Slf4j
@Configuration
@RequiredArgsConstructor
public class XMLTools {
@Value("${archive.path}")
private String path;//文件生成路径
@Value("${spring.application.name}")
private String systemName;//系统名
//附件处理开放接口
private final IWfAttachmentProvider attachmentPro;
public static void main(String[] args) throws IOException {
// Long start = System.currentTimeMillis();
// createFileXML(new ArchiveDoc());
// log.info("运行时间:"+ (System.currentTimeMillis() - start));
}
/**
* @author lyl
* 生成xml方法
*/
public static void createXml(){
try {
// 1、创建document对象
Document document = DocumentHelper.createDocument();
// 2、创建根节点rss
Element rss = document.addElement("rss");
// 3、向rss节点添加version属性
rss.addAttribute("version", "2.0");
// 4、生成子节点及子节点内容
Element channel = rss.addElement("channel");
Element title = channel.addElement("title");
title.setText("国内最新新闻");
// 5、设置生成xml的格式
OutputFormat format = OutputFormat.createPrettyPrint();
// 设置编码格式
format.setEncoding("UTF-8");
// 6、生成xml文件
File file = new File("rss.xml");
XMLWriter writer = new XMLWriter(new FileOutputStream(file), format);
// 设置是否转义,默认使用转义字符
writer.setEscapeText(false);
writer.write(document);
writer.close();
log.info("生成rss.xml成功");
} catch (Exception e) {
e.printStackTrace();
log.info("生成rss.xml失败");
}
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交