XML建模(简单易学)

时间:2025-03-25 21:52:26
  • package ;
  • import ;
  • import ;
  • import ;
  • import org.;
  • import org.;
  • import org.;
  • import org.;
  • import org.;
  • public class XmlRead {
  • private XmlRead() {
  • }
  • private static ConfigModel config=new ConfigModel();
  • static {
  • //读取xml文件
  • InputStream in=("");
  • SAXReader reads=new SAXReader();
  • //读取该文件得到一个文档
  • Document doc = null;
  • try {
  • doc = (in);
  • } catch (DocumentException e1) {
  • ();
  • }
  • //得到元素
  • Element el=();
  • //获取到action该节点
  • List<Element> action=("action");
  • for (Element e : action) {
  • //获取到action元素的
  • String path=("path");
  • String type=("type");
  • ActionModel actionModel=new ActionModel();
  • (path);
  • (type);
  • //在获取到action下的节点forward
  • List<Element> forward=("forward");
  • for(Element f:forward) {
  • //获取到forward节点的属性
  • String name=("name");
  • String path01=("path");
  • String redirect=("redirect");
  • ForwardModel forwar=new ForwardModel();
  • (name);
  • (path);
  • (redirect);
  • (forwar);
  • }
  • (actionModel);
  • }
  • }
  • public static ConfigModel getConfig() {
  • return config;
  • }
  • //测试
  • public static void main(String[] args) {
  • ConfigModel config=();
  • ActionModel action=("/studentAction");
  • ForwardModel forward = ("students");
  • (forward);
  • }
  • }