当前位置:网站首页>XML modeling
XML modeling
2022-06-25 02:59:00 【Chasing dream Zichen】
utilize dom4j+xpath Technical realization XML modeling
Mind mapping :

Case code :
public class ConfigTe {
// Configure default address
private static final String defual_path="../J2EE05/config.xml";
private ConfigTe() {
}
/** * Modeling methods * @param path Address * @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;
// obtain io flow
InputStream is = ConfigTe.class.getResourceAsStream(path);
// Reader
SAXReader sr = new SAXReader();
// Read configuration file , obtain document object
Document doc = sr.read(is);
// Use xpath Parse object
//config node
List<Node> config = doc.selectNodes("config");
ConfigMod configMod = new ConfigMod();
for (Node c : config
) {
//action node
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 node
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);
}
}
With ActionMod For example :
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;
}
/** * save forwar object * @param forward object */
public void put(ForwardMod forward){
this.action.put(forward.getName(),forward);
}
/** * Get the node * @param forname Primary key * @return forward object */
public ForwardMod get(String forname){
return this.action.get(forname);
}
}
边栏推荐
- 小米路由R4A千兆版安装breed+OpenWRT教程(全脚本无需硬改)
- UnityShader入门精要——表面着色器
- Xiaomi routing R4A Gigabit version installation feed+openwrt tutorial (the full script does not need to be hard modified)
- Difference between left join on and join on
- VSCode中如何实现点击DOM自动定位到相应代码行
- ARM汇编中的栈桢小结
- Using qdomdocument to manipulate XML files in QT
- AOSP ~ default attribute value
- PyTorch学习笔记(七)------------------ Vision Transformer
- C#实现水晶报表绑定数据并实现打印
猜你喜欢

nacos实践记录

random list随机生成不重复数

Computer wechat user picture decoded into picture in DAT format (TK version)
![Planification du réseau | [quatre couches de réseau] points de connaissance et exemples](/img/c3/d7f382409e99eeee4dcf4f50f1a259.png)
Planification du réseau | [quatre couches de réseau] points de connaissance et exemples

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

Xiaomi routing R4A Gigabit version installation feed+openwrt tutorial (the full script does not need to be hard modified)

记一次beego通过go get命令后找不到bee.exe的坑

Once beego failed to find bee after passing the go get command Exe's pit

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

用向量表示两个坐标系的变换
随机推荐
20年ICPC澳门站L - Random Permutation
Dirvish Chinese document of vim
How to uninstall CUDA
Enlightenment of using shadergraph to make edge fusion particle shader
F - Spices(线性基)
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(1)——迁移数据到节点1
调用系统函数安全方案
Tutoriel d'installation MySQL
Refresh mechanism of vie
Insurance can also be bought together? Four risks that individuals can pool enough people to buy Medical Insurance in groups
Leecode learning notes - the shortest path for a robot to reach its destination
Go synchronization waiting group
李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)
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.
The Oracle 11g RAC cluster database cannot be started due to directory permission errors
消息称一加将很快更新TWS耳塞、智能手表和手环产品线
Getting started with unityshader Essentials - PBS physics based rendering
怎么开户打新债 开户是安全的吗
PyTorch学习笔记(七)------------------ Vision Transformer
vie的刷新机制