First of all, we have to thank the developers who wrote the XPath for the Chinese documents written in China! Using XPath allows us to parse the XML document to become more flexible and simple.
PackageIt.xiehe.xml;ImportJava.io.File;Importjava.util.List;Importorg.dom4j.Document;Importorg.dom4j.DocumentException;ImportOrg.dom4j.Node;ImportOrg.dom4j.io.SAXReader;/** @ Impersonate user Login verification * @xml act as database storage data*/ Public classDemoxpath {//XPath User Login Verification Public Static voidMain (string[] args)throwsException {//user information is as followsString name = "AAA"; String Password= "123"; Saxreader Reader=NewSaxreader (); Document Document= Reader.read (NewFile ("Src/users.xml")); Node Node= Document.selectsinglenode ("//user[@name = '" +name+ "' and @password = '" + password + "']"); //List List =//document.selectnodes ("//user[@name = ' +name+ ' and @password = ' "+password+" '] "); if(node = =NULL) {System.out.println ("The password or account is wrong!" "); } Else { //SYSTEM.OUT.PRINTLN ("Login Successful! "); } }}
-------------------------Users----------------------------
<?xml version= "1.0" encoding= "UTF-8"?>
<users>
<user name= "AAA" password= "123" phone= "456" ></user>
<user name= "BBB" password= "789" phone= "123" ></user>
</users>
XPath parsing of XML documents