创建XML

需要的jar包:dom4j.github.io

// 创建document对象
Document document = DocumentHelper.createDocument();
// 根节点
Element root = document.addElement("root");
// 添加属性
root.addAttribute("id", "root");
// 添加子节点
Element head =  root.addElement("head");
Element body =  root.addElement("body");
// 添加内容
head.setText("hello world");
body.setText("hello body");
// 增加内容 ( 类似StringBuilder
head.addText(",this is head");
// 修改内容(再次set
body.setText("body内容已修改");
// 清除节点内容
body.clearContent();
// 删除节点
root.remove(body);
System.out.println(document.asXML());

解析XML

URL url = new URL("https://www.zhihu.com/rss");
SAXReader reader = new SAXReader();
Document document = reader.read(url);

相关文章:

  • 2021-04-16
  • 2022-01-25
  • 2022-01-23
  • 2021-10-18
  • 2021-10-30
  • 2021-08-16
  • 2022-12-23
猜你喜欢
  • 2021-11-08
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
相关资源
相似解决方案