当前位置:网站首页>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);
}
}
边栏推荐
- Can the polardb database be connected to the data source through MySQL
- 软件测试周刊(第77期):只要放弃一次,就会滋生放弃的习性, 原本可以解决的问题也会变得无法解决。
- LeetCode 210:课程表 II (拓扑排序)
- ACM. Hj75 common substring calculation ●●
- 36岁前亚马逊变性黑客,窃取超1亿人数据被判20年监禁!
- Once beego failed to find bee after passing the go get command Exe's pit
- PE file infrastructure sorting
- 保险也能拼购?个人可以凑够人数组团购买医疗保险的4大风险
- Introduction to database system
- Tell you about mvcc sequel
猜你喜欢

消息称一加将很快更新TWS耳塞、智能手表和手环产品线

Introduction to CUDA Programming minimalist tutorial

After reciting the eight part essay, I won the hemp in June

MATLAB主窗口与编辑器窗口分开为两个界面的解决办法

计网 | 【四 网络层】知识点及例题

使用ShaderGraph制作边缘融合粒子Shader的启示

Transformers Roberta如何添加tokens

Use xxl-job to customize tasks and schedule them

Copilot免费时代结束!学生党和热门开源项目维护者可白嫖

DSPACE set zebra crossings and road arrows
随机推荐
ERROR日志格式与注意点
MySQL learning notes -- addition, deletion, modification and query on a single table
After reciting the eight part essay, I won the hemp in June
Centos7.3 modifying MySQL default password_ Explain centos7 modifying the password of the specified user in MySQL
Planification du réseau | [quatre couches de réseau] points de connaissance et exemples
The era of copilot free is over! Student party and defenders of popular open source projects can prostitute for nothing
分布式事务解决方案和代码落地
Advanced mathematics | proficient in mean value theorem problem solving routines summary
Unity archive system - file in JSON format
Charles 抓包工具
数组-一口气冲完快慢指针
nacos实践记录
使用XXL-JOB自定义任务并调度
Random list random generation of non repeating numbers
JS regular matching numbers, upper and lower case letters, underscores, midlines and dots [easy to understand]
运行时修改Universal Render Data
C#实现水晶报表绑定数据并实现打印
計網 | 【四 網絡層】知識點及例題
Copilot免费时代结束!学生党和热门开源项目维护者可白嫖
@PostConstruct