当前位置:网站首页>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);
}
}
边栏推荐
- Getting started with unityshader - Surface Shader
- DSPACE设置斑马线和道路箭头
- Expressing the transformation of two coordinate systems with vectors
- Software testing weekly (issue 77): giving up once will breed the habit of giving up, and the problems that could have been solved will become insoluble.
- Insurance can also be bought together? Four risks that individuals can pool enough people to buy Medical Insurance in groups
- Refresh mechanism of vie
- Summary of knowledge points of computer level III (database) test preparation topics
- Mall project pc--- product details page
- 调用系统函数安全方案
- vie的刷新机制
猜你喜欢

Solution of separating matlab main window and editor window into two interfaces

CUDA编程入门极简教程

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

It is said that Yijia will soon update the product line of TWS earplugs, smart watches and bracelets

When they are in private, they have a sense of propriety

Getting started with unityshader Essentials - PBS physics based rendering

Introduction to CUDA Programming minimalist tutorial

Computer wechat user picture decoded into picture in DAT format (TK version)

AOSP ~ WIFI架构总览

Is it out of reach to enter Ali as a tester? Here may be the answer you want
随机推荐
It's 2022, and you still don't know what performance testing is?
Unity存档系统——Json格式的文件
怎么开户打新债 开户是安全的吗
Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (2) -- convert database to cluster mode
AI服装生成,帮你完成服装设计的最后一步
Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (3) -- set the database to archive mode
20 years ICPC Macau station L - random permutation
14 bs对象.节点名称.name attrs string 获取节点名称 属性 内容
UnityShader入门精要——PBS基于物理的渲染
Computer wechat user picture decoded into picture in DAT format (TK version)
ERROR日志格式与注意点
CMakeLists中的add_definitions()函数
Internship: use of SVN
Introduction to CUDA Programming minimalist tutorial
DSPACE set zebra crossings and road arrows
Once beego failed to find bee after passing the go get command Exe's pit
Getting started with unityshader - Surface Shader
调用系统函数安全方案
Solution of separating matlab main window and editor window into two interfaces
Pytorch learning notes (VII) ------------------ vision transformer