当前位置:网站首页>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);
}
}
边栏推荐
- Advanced mathematics | proficient in mean value theorem problem solving routines summary
- MySQL learning notes -- addition, deletion, modification and query on a single table
- mysql命令备份
- CMakeLists中的add_definitions()函数
- 消息称一加将很快更新TWS耳塞、智能手表和手环产品线
- AOSP ~ default attribute value
- 3 years of testing experience. I don't even understand what I really need on my resume. I need 20K to open my mouth?
- Unity archive system - file in JSON format
- 商城项目 pc----商品详情页
- CUDA编程入门极简教程
猜你喜欢

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

Leecode learning notes - the shortest path for a robot to reach its destination

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

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

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

Detailed explanation of cache (for the postgraduate entrance examination of XD)

Advanced mathematics | proficient in mean value theorem problem solving routines summary

AOSP ~ WIFI架构总览

left join on和 join on的区别

AI服装生成,帮你完成服装设计的最后一步
随机推荐
小米路由R4A千兆版安装breed+OpenWRT教程(全脚本无需硬改)
Lihongyi, machine learning 6 Convolutional neural network
Add in cmakelists_ Definitions() function
李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)
qt打包exe文件,解决“无法定位程序输入点_ZdaPvj于动态链接库Qt5Cored.dll”
Unity archive system - file in JSON format
14 BS object Node name Name attrs string get node name attribute content
好用的字典-defaultdict
MySQL command backup
Doak CMS article management system recommendation
How to click DOM to automatically locate the corresponding code line in vscode
数组-一口气冲完快慢指针
DSPACE set zebra crossings and road arrows
保险也能拼购?个人可以凑够人数组团购买医疗保险的4大风险
love
The Oracle 11g RAC cluster database cannot be started due to directory permission errors
自动化测试
Practice and Thinking on process memory
Transformers Roberta如何添加tokens
ACM. HJ75 公共子串计算 ●●