当前位置:网站首页>Dom4j+xpath parsing XML files
Dom4j+xpath parsing XML files
2022-06-22 08:03:00 【Chasing dream Zichen】
dom4j+xpath analysis xml file
dom4j+xpath analysis xml file document for java SAX
1)xpath Similar to select sentence ;
2)Document With nodes (Node) form : Elements . node 、 attribute 、 Text etc.
3) Node( node ) Element( Elements ) difference getText();
3)selectNodes() Get all child nodes under the node ;
4)selectSingleNode() Get single node information ;
5) xpath grammar :/( Positioning path )、@( get attribute )
public static void main(String[] args) throws DocumentException {
// obtain io flow
InputStream is = ConfigText.class.getResourceAsStream("config.xml");
// Reader
SAXReader sr = new SAXReader();
// Read configuration file , obtain document object
Document doc = sr.read(is);
// Use xpath analysis document object
//config node
List<Node> config = doc.selectNodes("config");
// Traverse config node
for (Node c:config
) {
Map<String,ActionMod> configmap = new HashMap<>();
//action node
List<Node> action = doc.selectNodes("config/action");
for (Node a:action
) {
Map<String,ForwardMod> actionmap = new HashMap<>();
Element ea =(Element) a;
//forward node
List<Node> forward = doc.selectNodes("config/action/forward");
for (Node f:forward
) {
Element el =(Element) f;
actionmap.put(el.attributeValue("name"),new ForwardMod(el.attributeValue("path"),el.attributeValue("redirect")));
}
configmap.put(ea.attributeValue("path"),new ActionMod(actionmap,ea.attributeValue("type")));
}
System.out.println(configmap);
}
}
边栏推荐
- Restrict input type (multiple methods)
- Concatenate the specified character at the end of a number in a string
- Leetcode 172 Zero after factorial (2022.06.21)
- AudioQueue
- MySQL index
- 数据可视化优秀案例
- 关于菲涅尔现象
- 模板代码概述
- Relative positioning, absolute positioning, fixed positioning
- Some suggestions on Oracle SQL query return optimization
猜你喜欢
随机推荐
Cocoapods problem record
SQL server changes the primary key index to a non clustered index
lr 2022超详细安装教程「最新」
Expérience électrique en mode - - expérience 2 circuit d'amplification de source commune JFET
Mt4/mql4 getting started to proficient in foreign exchange EA automatic trading tutorial - special identification of the K line on the chart
AudioQueue
【Oracle 数据库】奶妈式教程 day13 日期函数
Mt4/mql4 getting started to mastering EA tutorial lesson 5 - common functions of MQL language (V) - common functions of account information
Difference between ID instancetype nsobject *
力扣(LeetCode)172. 阶乘后的零(2022.06.21)
(8) Sequence stack and chain stack
AutoCAD 2020.3 Chinese Version (old version)
Layer drawing method
MySQL master-slave replication
The significance of code coverage testing to programming white and its application
Baidu Post Bar crawler crawls to the middle of the building
模电实验——实验二 JFET共源极放大电路
代码覆盖率测试对编程小白的意义及其使用方法
Some problems caused by null data in MySQL
A glimpse of easy rule








