-1

これは一番下の
プライベート静的文字列getTagValue(String sTag、Element eElement){NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();

        Node nValue = (Node) nlList.item(0);

        return nValue.getNodeValue();
    }

}
4

1 に答える 1

1

メイン関数を更新します...

 public static void main(String[] args) 
        { 
            try 
            {     
                File fXmlFile = new File(".xml");  
                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();   
                DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();   
                Document doc = dBuilder.parse(fXmlFile);        
                doc.getDocumentElement().normalize();          
                NodeList nList = doc.getElementsByTagName("user");   

                System.out.println("============================================");
                System.out.println("==========Welcome to Multiuser ATM=========="); 
                System.out.println("============================================\n\n"); 
                System.out.println("Please enter your Account Number:"); 
                int acno = sc.nextInt();       
                System.out.println("Please enter your Password:");  
                int password = sc.nextInt();        
                System.out.println("Your Account Balance is:"); 
                System.out.println("Please choose your option:"); 

    //------------You just have to insert below code---------------------

                for (int temp = 0; temp < nList.getLength(); temp++)
                {
                    Node nNode =  nList.item(temp);

                    if (nNode.getNodeType() == Node.ELEMENT_NODE)
                    {
                        Element eElement = (Element) nNode;
                        int ano = Integer.parseInt(getTagValue("acno", eElement));
                        System.out.println("ANO:  "+ano);
                        if(ano == acno)
                        {
                            System.out.println("Acno:    "+acno+"  ANO:  "+ano);
                            int pass = Integer.parseInt(getTagValue("password", eElement));
                            if(pass == password)
                                System.out.println("Password:    "+password+"  pass:  "+pass);
                        }                   
                    }
                }
            }   
            catch (Exception e)  
            {
                e.printStackTrace(); 
            } 
于 2012-04-09T05:54:52.347 に答える