Advertisement
Guest User

userExists

a guest
Oct 25th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. public boolean userExists(String username){
  2.         //System.out.println("achi1hth");
  3.        
  4.         try{
  5.             File fXmlFile = new File(filePath);
  6.             DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  7.             DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
  8.             System.out.println("hfjhf");
  9.             Document doc = dBuilder.parse(fXmlFile);
  10.             System.out.println("fdg");
  11.             doc.getDocumentElement().normalize();
  12.             //System.out.println("achi");
  13.             NodeList nList = doc.getElementsByTagName("user");
  14.            
  15.             for (int temp = 0; temp < nList.getLength(); temp++) {
  16.                 Node nNode = nList.item(temp);
  17.                 if (nNode.getNodeType() == Node.ELEMENT_NODE) {
  18.                     Element eElement = (Element) nNode;
  19.                     if(getTagValue("username", eElement).equals(username)){
  20.                         return true;
  21.                     }
  22.                 }
  23.             }
  24.             return false;
  25.         }
  26.         catch(Exception ex){
  27.             System.out.println("Database exception : userExists()");
  28.             return false;
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement