XPath

来源:互联网 发布:市政工程师待遇知乎 编辑:程序博客网 时间:2024/05/01 09:49
XPath提取xml文档数据
XPath文档---XPathTutorial----General_chi
语法:
/ 必须从根节点
// 表示
查找某值 ' "+变量名+"'
String name ="aaa";
String password ="123";
SAXReader saxReader = new SAXReader();
Documetn document = saxReader.read(new File("user.xml"));
Node node = document.selectSingleNode("//user[@name='"+name+"' and @password='"+password+"']");
if(node==null)
{
System.out.println("用户名或密码错误");
}
else{
System.out.println("登录成功");
}

原创粉丝点击