xml基础知识(7)
来源:互联网 发布:淘宝卖的dw是真的吗 编辑:程序博客网 时间:2024/04/29 17:09
xpath:用于确定xml文档中指定元素的位置
//:表示全部
/:表示某一层//user[@name="aaa"and @password="123"]:表示所有user元素下name属性为aaa,password属性为123的元素、
实例:
xml文档:
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user id="1" username="aaa" password="123"></user>
<user id="2" username="bbb" password="123"></user>
</users>
提取代码:
public static void main(String[] args) throws DocumentException{
String username = "ccc";
String password = "123";
//解析xml文档
SAXReader reader = new SAXReader();
Document document = reader.read(new File("src/user.xml"));
//xpath提取xml文档
Node node = document.selectSingleNode("//user[@username='"+username+"' and @password='"+password+"']");
//判定
if(node==null){
System.out.println("登陆失败");
}else {
System.out.println("登录成功");
}
}
阅读全文
0 0
- xml基础知识(7)
- xml基础知识(一)
- xml基础知识(1)
- xml基础知识(2)
- xml基础知识(3)
- xml基础知识(4)
- XML基础知识(5)
- xml基础知识(6)
- xml基础知识(8)
- xml基础知识(9)
- xml基础知识
- xml基础知识
- xml基础知识
- XML基础知识
- XML基础知识
- xml基础知识
- XML基础知识
- xml基础知识
- ES6基础学习(一)
- Android:res之selector背景选择器
- 安卓实现"再按一次退出程序"效果
- 矩阵快速幂 模板
- trait的基本声明和使用
- xml基础知识(7)
- 算法题目---从上往下打印二叉树
- SpringCloudStream 构建消息驱动的微服务框架 集成kafka_http://blog.spring-cloud.io/blog/sc-stream.html
- Python3.x 进阶之路-翻译模块
- JSP 教程
- 算法系列——Combinations
- 猴子分桃等。。
- C#多线程中的异常处理
- 【STL】hdu 6015 Skip the Class