更新您的主要功能...
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-08 16:07:33
當我輸入帳號時,我的java程序必須讀取輸入並驗證上面給出的xml文件的輸入值。例如,如果我輸入1111當java請求輸入帳號時,java程序必須檢查是否1111存在於該XML文件中或沒有,如果找到,我的Java程序必須去下面一行來請求密碼... – 2012-04-08 16:30:53
你有所有的邏輯來讀取你的try catch catch塊中的賬號no將它移動到嘗試阻止。 – 2012-04-08 16:46:18