当前位置:网站首页>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);
}
}
边栏推荐
- Is it safe for Guoxin golden sun to open an account in the steps of opening new bonds
- ACM. Hj70 matrix multiplication calculation amount estimation ●●
- Summary of stack frame in arm assembly
- leecode学习笔记-机器人走到终点的最短路径
- 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 era of copilot free is over! Student party and defenders of popular open source projects can prostitute for nothing
- Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (1) -- migrate data to node 1
- Getting started with unityshader - Surface Shader
- QT package the EXE file to solve the problem that "the program input point \u zdapvj cannot be located in the dynamic link library qt5cored.dll"
- Charles packet capturing tool
猜你喜欢

Array - fast and slow pointer in one breath

Before the age of 36, Amazon transgender hackers were sentenced to 20 years' imprisonment for stealing data from more than 100million people!

电脑端微信用户图片DAT格式解码为图片(TK版)

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

Lihongyi, machine learning 6 Convolutional neural network

MySql安装教程

AI自己写代码让智能体进化!OpenAI的大模型有“人类思想”那味了
![[STL source code analysis] configurator (to be supplemented)](/img/87/0ed1895e9cdb5327411c0c9cb0197f.png)
[STL source code analysis] configurator (to be supplemented)
![Network planning | [four network layers] knowledge points and examples](/img/c3/d7f382409e99eeee4dcf4f50f1a259.png)
Network planning | [four network layers] knowledge points and examples

消息称一加将很快更新TWS耳塞、智能手表和手环产品线
随机推荐
F - spices (linear basis)
分布式事务解决方案和代码落地
1-6 build win7 virtual machine environment
doak-cms 文章管理系统 推荐
計網 | 【四 網絡層】知識點及例題
20年ICPC澳门站L - Random Permutation
npm包发布详细教程
Transformers Roberta如何添加tokens
[STL source code analysis] configurator (to be supplemented)
Lihongyi, machine learning 6 Convolutional neural network
MySql安裝教程
202112-2 序列查询新解
Charles 抓包工具
Centos7.3 modifying MySQL default password_ Explain centos7 modifying the password of the specified user in MySQL
Go synchronization waiting group
Cloud native database vs traditional database
[i.mx6ul] u-boot migration (VI) network driver modification lan8720a
[analysis of STL source code] functions and applications of six STL components (directory)
记一次beego通过go get命令后找不到bee.exe的坑
Leecode learning notes - the shortest path for a robot to reach its destination