当前位置:网站首页>XML file parsing
XML file parsing
2022-07-19 12:57:00 【Customer bank】
Catalog
One .Java Three configuration locations and reading methods of configuration files in
Two .dom4j The common method of
3、 ... and . analysis XML file
One .Java Three configuration locations and reading methods of configuration files in
1. Same bag
Class name .class.getResourceAsStream(" File name ")
2. The root path
Class name .class.getResourceAsStream("/ File name ")
3.WIN-INF Safe path
context.getResourceAsStream("/WIN-INF/ File path ")
Two .dom4j The common method of
- selecNodes: Get the element
selectSingleNode: Get a single element
getRootElement(): Get the root element
attributeValue: Only elements can click this method to get values
getText: Get the element text
3、 ... and . analysis XML file
- Let's configure the location and read xml When configuring a file , You need to put these below the picture jar Package import .

- xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE config[
<!ELEMENT config (action*)>
<!ELEMENT action (forward*)>
<!ELEMENT forward EMPTY>
<!ATTLIST action
path CDATA #REQUIRED
type CDATA #REQUIRED
>
<!ATTLIST forward
name CDATA #REQUIRED
path CDATA #REQUIRED
redirect (true|false) "false"
>
]>
<config>
<action path="/studentAction" type="org.lisen.mvc.action.StudentAction">
<forward name="students" path="/students/studentList.jsp" redirect="false"/>
</action>
<action path="/bookAction" type="org.lisen.mvc.action.bookAction">
<forward name="books" path="/books/bookList.jsp" redirect="false"/>
</action>
</config>- analysis xml File operations
package com.yjx.test; import java.io.InputStream; import java.util.Iterator; import java.util.List; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; public class XmlRead { public static void main(String[] args) throws Exception { // Read xml file InputStream in=XmlRead.class.getResourceAsStream("config.xml"); SAXReader reads=new SAXReader(); // Read the file to get a document Document doc=reads.read(in); // Get the element Element el=doc.getRootElement(); // Get action The node List<Element> action=el.selectNodes("action"); for (Element e : action) { // Get action Elemental String path=e.attributeValue("path"); String type=e.attributeValue("type"); System.out.println(path); System.out.println(type); // In the access to action Next node forward List<Element> forward=e.selectNodes("forward"); for(Element f:forward) { // Get forward Properties of a node String name=f.attributeValue("name"); String path01=f.attributeValue("path"); String redirect=f.attributeValue("redirect"); System.out.println(name); System.out.println(path01); System.out.println(redirect); } } } }That's all for today's study !!!
边栏推荐
- The active and standby cache of redis cluster is full, causing frequent active and standby switchover
- Azkaban 安装文档
- O & M LITTLE WHITE Growth record - architecture week 6
- 超声波传感器(CH101&ch201) - Ⅰ
- mysql数据库表增添字段,删除字段、修改字段的排列等操作,还不快来
- Ultrasonic sensor (ch101 & ch201) - Ⅱ
- Uio-66 - (COOH) 2 modified polyamide nanofiltration membrane | zif-8/pvp composite nanofiber membrane | uio-66-nh2 modified polyamide nanofiltration membrane
- Lazy to the bone, I am too lazy to write articles in CSDN. I write articles based on selenium simulation
- MOF customized material | NH (2) -uio66/rgo Graphene Oxide Nanocomposite | methylene blue loaded zif-90 nanoparticles
- Mycat2 builds MySQL master-slave separation
猜你喜欢

又错了,字节对齐及#pragma pack的使用

2022 global developer salary exposure: China ranks 19th, with an average annual salary of $23790

基于STM32设计的云端健康管理系统(采用阿里云物联网平台)

Stable super odds, 9 years old mixin | 2022 Jincang innovative product launch was successfully held

MOF customized material | NH (2) -uio66/rgo Graphene Oxide Nanocomposite | methylene blue loaded zif-90 nanoparticles

AE how to make Nebula particle special effects

35岁以上的测试/开发程序员职业生涯走向,是职场转折点吗?

松下A6伺服驱动器外部绝对值光栅尺全闭环参数设置

Return to risk ratio: the most important indicator of investment opportunities 2020-03-14

Uio-66 | fe3o4/cu3 (BTC) 2 metal organic framework (MOF) nanocomposites supported on silver nanoparticles | nagdf4:yb, er upconversion nanoparticles @zif-8
随机推荐
O & M LITTLE WHITE Growth record - architecture week 6
2022 safety officer-c certificate title and answer
Enrollment publicity - Jiangnan University
Nitrogen heterocyclic molecule modified uio-66-nh2 | polyethyleneimine modified uio-66-nh2| [email protected] @Zif67 nanomaterial
【错误记录/selectpicker】dropdown menu显示位置出现偏移
Uio-66 | fe3o4/cu3 (BTC) 2 metal organic framework (MOF) nanocomposites supported on silver nanoparticles | nagdf4:yb, er upconversion nanoparticles @zif-8
最懂你的服装设计师是AI?让用户 “凭心意” 生成数字服装#Adidas OZWORLD
2022 global developer salary exposure: China ranks 19th, with an average annual salary of $23790
Minimum exchange times
The difference and use between get request and post request
Azkaban 安装文档
动态内存规划
Common bug precautions of audio control
Knowledge sorting of MySQL
Do you still need to release the database connection manually with typeorm
超声波传感器(CH101&ch201) - Ⅱ
MatrixCube揭秘 101——MatrixCube的功能与架构
LeetCode_ Prefix and_ Medium_ 523. Continuous subarrays and
Google developer community sharing - flutter animation sharing has been released
ASP.NET协同OA办公服务管理平台源码
