当前位置:网站首页>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);
}
}
边栏推荐
- 把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(2)——将数据库转换为集群模式
- 使用ShaderGraph制作边缘融合粒子Shader的启示
- Leetcode 210: curriculum II (topological sorting)
- Internship: use of SVN
- 14 BS object Node name Name attrs string get node name attribute content
- [live review] battle code pioneer phase 7: how third-party application developers contribute to open source
- Computing service network: a systematic revolution of multi integration
- DSPACE的性能渲染问题
- Is it safe to open an account in the way of winning 100% of the new bonds
- 软件测试周刊(第77期):只要放弃一次,就会滋生放弃的习性, 原本可以解决的问题也会变得无法解决。
猜你喜欢

3 years of testing experience. I don't even understand what I really need on my resume. I need 20K to open my mouth?

Difference between left join on and join on

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

Can automate - 10k, can automate - 20K, do you understand automated testing?

李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)

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

用向量表示两个坐标系的变换

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

好用的字典-defaultdict

20年ICPC澳门站L - Random Permutation
随机推荐
Array - fast and slow pointer in one breath
使用ShaderGraph制作边缘融合粒子Shader的启示
Lihongyi, machine learning 6 Convolutional neural network
Refresh mechanism of vie
Can automate - 10k, can automate - 20K, do you understand automated testing?
AOSP ~ 默认属性值
好用的字典-defaultdict
Dirvish Chinese document of vim
Practice and Thinking on process memory
Performance rendering of dSPACE
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(3)—— 把数据库设置为归档模式
[i.mx6ul] u-boot migration (VI) network driver modification lan8720a
ACM. HJ75 公共子串计算 ●●
Post competition summary of kaggle patent matching competition
random list随机生成不重复数
高数 | 精通中值定理 解题套路汇总
Getting started with unityshader Essentials - PBS physics based rendering
CUDA编程入门极简教程
14 bs对象.节点名称.name attrs string 获取节点名称 属性 内容
@PostConstruct