模糊查询
XML 第一种存储方式,使用节点的InnerText 存储数据
user1.xml 片段如下:
1 | <?xml version="1.0" encoding="utf-8" ?> |
XPath 查询XML 代码如下:
//等值查询
string xpath = “users/user[username=’huo’ and password=’123’]”;
//模糊查询
string xpath = “users/user[contains(username,’huo’) and contains(password,’123’)]”;
XML 第二种存储方式,使用XMl 节点属性属性存储数据
user2.xml 片段如下:
1 | <users> |
XPath 查询XML 代码如下:
//xpath查询如:加”@” 用以查询属性值
//等值查询:
string xpath = “users/user[@username=’huo’ and @password=’123’]”;
//模糊查询:
string xpath = “users/user[contains(@username,’huo’) and contains(@password,’123’)]”;