import javax.xml.parsers.*;
import org.w3c.dom.*;public class dom{
public static void main(String[] args){
try{
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc=builder.parse("candidate.xml");
NodeList nl=doc.getElementsByTagName("PERSON");
for(int i=0;i<nl.getLength();i++){
Element node=(Element)nl.item(i);
System.out.print("NAME: ");
System.out.println(node.getElementsByTagName("NAME").item(0).getFirstChild().getNodeValue());
System.out.print("ADDRESS: ");
System.out.println(node.getElementsByTagName("ADDRESS").item(0).getFirstChild().getNodeValue());
System.out.print("TEL: ");
System.out.println(node.getElementsByTagName("TEL").item(0).getFirstChild().getNodeValue());
System.out.print("FAX: ");
System.out.println(node.getElementsByTagName("FAX").item(0).getFirstChild().getNodeValue());
System.out.print("EMAIL: ");
System.out.println(node.getElementsByTagName("EMAIL").item(0).getFirstChild().getNodeValue());

System.out.println();
}
}catch(Exception e){
e.printStackTrace();
}
}
}