码迷,mamicode.com
首页 > 其他好文 > 详细

XML的解析

时间:2019-05-24 12:51:13      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:single   eval   rop   对象   加载   dom4j   val   存放位置   tco   

XML的解析

  1. java中配置文件的三种配置位置及读取方式

       1.1  XML*.properties(属性文件)

         1*.properties文件

             Key=value

             #注释

           //util包下的属性文件类

          Properties    properties=new Properties();

           //加载一个properties

           Properties.load(is);

           //某一个键的值

        Properties.getProperty(“键名”);

 

           1.2 存放位置

            1.2.1   src根目录下

            类名:class.getresourceAsStream(“/config.properties”);

             1.2.2   与读取配置文件的类在同一包

                类名:class.getResourceAsStream(“config2properties.”);

            1.2.3 WEB-INF(或其子目录下)

                 ServletContext sc=this.getServletContext();

       InputStreais=sc.getResourceAsStream("/WEB-INF/test.properties");

 

 

           2 dom4j+xpath 解析xml 文件

               Xpath 等同于数据库的select语句

 

             document.selectNodes(xpath);//查一组

             document.selectSingleNode(xpath);//查单个

 

 

                  DOM由节点组成

             Node

              元素节点

             属性节点

               文本节点

              3 dom4J 解析

              SAXReader                       解析器

            Read(XML路径)                得到document对象

             getRootElement               获取根节点

               Element(节点名称)             获取根节点下的指定节点信息

              attributeValue(属性名)        获取属性值

            Element(节点名称)              获取节点的Element对象

             getText()                     获取节点的值

XML的解析

标签:single   eval   rop   对象   加载   dom4j   val   存放位置   tco   

原文地址:https://www.cnblogs.com/xmf3628/p/10917240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!