简介:
1. JAVA XML API
2. Dom4j is a simple and flexible open source library for working with XML, XPath and XSLT on the Java platform using the Java Collections Framework with full integration with DOM, SAX and JAXP.
概念:
1. XML
全称:Extensible Markup Language,可扩展标记语言
定义:用于标记电子文件使其具有结构性的标记语言
作用:提供统一的方法来描述和交换独立于应用程序或供应商的结构化数据
2. DOM
全称:Document Object Model,文档对象模型
定义:The Document Object Model is a platform-and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the the presented page.
文档对象模型作为与平台和语言无关的接口,允许程序和脚本语言动态访问和更新文档的内容,结构和样式。使用文档对象模型的文件可以被进一步处理,同时处理的结果可以合并到已显示的页面中。
为什么选择DOM4J解析器
1. 常见解析器
DOM是基于平台、语言无关的W3C标准。基于树的层次,其优点是可以移植,编程容易,开发人员只需要调用建树的指令。缺点是加载大文件不理想。
SAX是基于事件模型的,它在解析XML文档的时候可以触发一系列的事件,当发现给定的tag时候,他可以激活一个回调方法,告诉该方法制定的标签已经找到。类似与流媒体的解析方式,所以在加载大文件的时候效果不错。
JDOM是想成为Java特定文档模型。简化与XML的交互并且比使用DOM实现更快。使用的是具体类不使用借口,运用大量的Collection类,方便程序员。To provide a complete, Java-based solution for accessing, manipulating, and outputting XML data from Java code.
DOM4J是一个独立的开发结果,非常优秀的Java XML API, 具有性能优异、功能强大和极端易用的特点,同时是一个开源工具。
2. 原因
DOM4J性能最好,连Sun的JAXM也在用DOM4J。目前许多开源项目中大量采用DOM4J,例如Hibernate也用DOM4J来读取XML配置文件。如果不考虑可移植性,那就采用DOM4J.
[list]
DOM4J使用
1. 方法列表
创建SAX解析器,以便通过解析器将XML转换成DOM4J树形模型。
//SAXReader creates a DOM4J tree from SAX parsing events.
//The actual SAX parser that is used by this class is configurable so you can use your favourite SAX parser if you wish. 事实上本类所使用的SAX解析器是可以配置的,因此可以选择你钟爱的SAX解析器。
//DOM4J comes configured with its own SAX parser so you do not need to worry about configuring the SAX parser. DOM4J来配置自己的SAX解析器,因此你不必要担心如何配置SAX解析器了。
new SAXReader();
SAXReader提供了读取File文件的方法,更多方法见源码。
//Reads a Document from the given File.
//We cannot convert the file to an URL because if the filename contains '#' characters, there will be problems with the URL in the InputSource
read(File file)
DOM4J Document提供了获取根节点方法
//Returns the root Element for this document.
Element org.dom4j.Document.getRootElement()
获取根元素名称
//getName returns the name of this node. This is the XML local name of the element, attribute, entity or processing instruction. For CDATA and Text nodes this method will return null.
String org.dom4j.Node.getName()
通过名称获取元素
//Returns the first element for the given local name and any namespace.
Element org.dom4j.Element.element(String name)
获取直接子元素对象List
//Returns the elements contained in this element. If this element does not contain any elements then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.
List org.dom4j.Element.elements()
获取元素文本
//Returns the text value of this element without recursing through child elements. This method iterates through all Text, CDATA and Entity nodes that this element contains and appends the text values together.
String org.dom4j.Element.getText()
其它方法略(如取得元素属性、增加、删除元素等方法),详情参看源码
2. 实例
下载jar包,见Reference [1]
Reference
1. http://sourceforge.net/projects/dom4j/
2. http://www.w3.org/DOM/
3. http://jdom.org/
分享到:
相关推荐
From_LNK_to_RCE:Finding_bugs_in_Windows_Shell_Link_Parser 应急响应 AI 安全威胁 自动化 信息安全研究
work in progress (WIP) , I'm always update this repo when the new bugs release.特权升级(漏洞和其他研究):特权文件操作Bug到SYSTEM shell(技术):服务帐户拥有SYSTEM特权(令牌模拟):工具: James ...
Debug_It!_Find,_Repair,_and_Prevent_Bugs_in_Your_Code.
discovRE__Efficient_Cross-Architecture_Identification_of_Bugs_in
JEE_TOMEE_BUGS_SAMPLE_PROJECT_A 用于向 TomeEE 提交错误的示例项目 此示例项目旨在比较 JEE 代码部署到不同容器,即 Weblogic、Glassfish 和 Tomee。 它的主要目标是找出 Tomee 容器上的错误。 在第一次推送到...
2019年4月5日 sv_pure_bypass 是的 ?? 2019年5月 sv_pure_bypass_2 是的 ?? 2019年10月 sv_pure_bypass_3 是的 2020年7月24日 , 和 sv_pure_bypass_4 是的 2020年6月8日 和 sv_pure_bypass_5 是的 2020...
discovRE: Efficient Cross-Architecture Identification of Bugs in Binary Code是发表在NDSS'16会议上的论文。本文在SP'15的基础上提出了在效率和效果上都有提高的跨架构二进制代码漏洞检测方案。 Abstract & ...
reproduce_kernel_bugs 重现Syzkaller发现的内核错误,并提供一些有用的脚本进行重现
cmake_cache_bugs 一个回购,重点介绍CMake缓存变量的问题 第1期 增量构建错误。 第2期 未使用的缓存变量问题。
信息安全_数据安全_Fuzzing_AOSP_for_Non-crash_bugs 漏洞分析 数据脱敏 数据智能 工控安全 漏洞挖掘
这些错误将包括不应再使用(不推荐使用)的标签,导致调试或掉毛错误的错误以及应避免的语法。 下面提供的资源将帮助您识别这些错误。资源 指示使用codeandbox克隆此仓库在打开一个新项目单击右上角的“创建沙箱”...
自述文件 该项目旨在通过提高租户整体体验并为他们提供使用服务的小激励机制,激励他们更频繁地使用租车服务。 要点概述和解释如下: 拼车模型 登录该应用后,您可以预订所需日期和时间的汽车。...
类似于VC中workspace的控件,是我从CJ60Lib库中提取出来的并做了些修改,不依赖于CJ60Lib库,能够使程序更小,而且还修复了两个重要的bug:1.程序最小化,并恢复后,子控件不重绘。2.在controlbar处于浮动状态时,主...
primer on dns find bugs where look for bugs
安装findbugs插件,及插件说明,经过测试。值得下载,超好用
A static analysis tool to find bugs in Java programs
Work around rename bugs in some systems for Linux v2.13.6.
zlip 单片机网络协议在在STM32 10x系列上的移植,并修复原版本bugs
Analysing Perl s printf function family format string bugs and exploitation. by CANVAS.
文件找回软件。就算是格式化之后都能找回