- 时间:2020-09-15 17:08 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:Java生成和解析XML格式文件和字符串的实例代码
1、基础知识:
Java解析XML一般有四种方法:DOM、SAX、JDOM、DOM4J。
2、使用介绍
1)、DOM
(1)简介
由W3C(org.w3c.dom)提供的接口,它将整个XML文档读入内存,构建一个DOM树来对各个节点(Node)进行操作。优点就是整个文档都一直在内存中,我们可以随时访问任何节点,并且对树的遍历也是比较熟悉的操作;缺点则是耗内存,并且必须等到所有的文档都读入内存才能进行处理。
(2)示例代码:
[url=http://tools.jb51.net/code/xmljson]http://tools.jb51.net/code/xmljson[/url]
[b]在线格式化XML/在线压缩XML:[/b][b]
[/b][url=http://tools.jb51.net/code/xmlformat]http://tools.jb51.net/code/xmlformat[/url]
[b]XML在线压缩/格式化工具:
[/b][url=http://tools.jb51.net/code/xml_format_compress]http://tools.jb51.net/code/xml_format_compress[/url]