当前位置:网站首页>XML建模
XML建模
2022-06-24 23:52:00 【追梦梓辰】
利用dom4j+xpath技术实现XML建模
思维导图:

案例代码:
public class ConfigTe {
//配置默认地址
private static final String defual_path="../J2EE05/config.xml";
private ConfigTe() {
}
/** * 建模方法 * @param path 地址 * @return * @throws DocumentException */
public static ConfigMod createConfigTe(String path) throws DocumentException {
String actiontype = null;
String actionpath = null;
String name = null;
String paths = null;
String redirect= null;
ActionMod am = null;
//获取io流
InputStream is = ConfigTe.class.getResourceAsStream(path);
//读取器
SAXReader sr = new SAXReader();
//读取配置文件,获取document对象
Document doc = sr.read(is);
//使用xpath解析对象
//config节点
List<Node> config = doc.selectNodes("config");
ConfigMod configMod = new ConfigMod();
for (Node c : config
) {
//action节点
List<Node> action = c.selectNodes("action");
for (Node a : action
) {
am = new ActionMod();
Element ea = (Element) a;
actiontype = ea.attributeValue("type");
actionpath = ea.attributeValue("path");
am.setPath(actionpath);
am.setType(actiontype);
//forward节点
List<Node> forward = a.selectNodes("forward");
for (Node f : forward
) {
Element el = (Element) f;
name = el.attributeValue("name");
paths = el.attributeValue("path");
redirect = el.attributeValue("redirect");
ForwardMod fm = new ForwardMod(name, paths, redirect);
am.put(fm);
}
configMod.put(am);
}
}
return configMod;
}
public static ConfigMod createConfigTe() throws DocumentException {
return createConfigTe(defual_path);
}
public static void main(String[] args) throws DocumentException {
ConfigMod configTe = ConfigTe.createConfigTe();
ActionMod s = configTe.get("/regAction");
System.out.println(s);
ForwardMod f =s.get("failed");
System.out.println(f);
}
}
以ActionMod 为例:
public class ActionMod {
private Map<String,ForwardMod> action = new HashMap<>();
private String type;
private String path;
@Override
public String toString() {
return "ActionMod{" +
"action=" + action +
", type='" + type + '\'' +
", path='" + path + '\'' +
'}';
}
public ActionMod(Map<String, ForwardMod> action, String type, String path) {
this.action = action;
this.type = type;
this.path = path;
}
public ActionMod(Map<String, ForwardMod> action, String type) {
this.action = action;
this.type = type;
}
public ActionMod() {
}
public Map<String, ForwardMod> getAction() {
return action;
}
public void setAction(Map<String, ForwardMod> action) {
this.action = action;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
/** * 存forwar对象 * @param forward 对象 */
public void put(ForwardMod forward){
this.action.put(forward.getName(),forward);
}
/** * 拿到节点 * @param forname 主键 * @return forward对象 */
public ForwardMod get(String forname){
return this.action.get(forname);
}
}
边栏推荐
- 36岁前亚马逊变性黑客,窃取超1亿人数据被判20年监禁!
- CMakeLists中的add_definitions()函数
- 计网 | 【四 网络层】知识点及例题
- ACL access control of squid proxy server
- AOSP ~ 默认属性值
- Dirvish Chinese document of vim
- 李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)
- 给你讲懂 MVCC 续篇
- Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (3) -- set the database to archive mode
- 用向量表示两个坐标系的变换
猜你喜欢

mysql学习笔记--单张表上的增删改查

ProcessOn制作ER过程(自定义)

Difference between left join on and join on

使用ShaderGraph制作边缘融合粒子Shader的启示
![[live review] battle code pioneer phase 7: how third-party application developers contribute to open source](/img/ad/26a302ca724177e37fe123f8b75e4e.png)
[live review] battle code pioneer phase 7: how third-party application developers contribute to open source

Introduction to CUDA Programming minimalist tutorial

【STL源码剖析】STL六大组件功能与运用(目录)

AI clothing generation helps you complete the last step of clothing design

3 years of testing experience. I don't even understand what I really need on my resume. I need 20K to open my mouth?

Pytorch learning notes (VII) ------------------ vision transformer
随机推荐
打新债是不是骗局 开户是安全的吗
E - average and median
Advanced mathematics | proficient in mean value theorem problem solving routines summary
202112-2 序列查询新解
C#实现水晶报表绑定数据并实现打印
AI clothing generation helps you complete the last step of clothing design
消息称一加将很快更新TWS耳塞、智能手表和手环产品线
Performance rendering of dSPACE
Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?
Introduction to CUDA Programming minimalist tutorial
Charles packet capturing tool
Charles 抓包工具
It's 2022, and you still don't know what performance testing is?
Once beego failed to find bee after passing the go get command Exe's pit
automated testing
Wechat applet obtains the parameters carried after scanning the QR code
高速缓存Cache详解(西电考研向)
李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)
运行时修改Universal Render Data
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(4)—— 修改 oracle11g rac 集群的 scanIP