try {
    File file = new File("/Users/Alex Ting/Desktop/test2/MovieList.xml");

    DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

    Document doc = dBuilder.parse(file);

    NodeList movielist = doc.getElementsByTagName("movie");
    for(int i =0;i<movielist.getLength(); i++){
        Node m=movielist.item(i);
        Element movie = (Element) m;
        String movieID = movie.getAttribute("id");

        NodeList mnamelist=movie.getChildNodes();
        for(int j=0;j<movielist.getLength(); j++){
        Node n = mnamelist.item(j);
        Element name = (Element) n;
        //System.out.println("Movie ID: "+ movieID +"\n"+ name.getTagName()+ ": "+ name.getTextContent());
        //System.out.println(name.getTagName()+ ": "+ name.getTextContent());
        System.out.println("Movie Id :"+movie.getAttribute("id"));

        System.out.println(name.getTagName()+ ": "+ name.getTextContent());


     } catch (Exception e) {

my xml file

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <movie id="1001">
        <duration> 90 mins </duration>

    <movie id="1002">
        <title>The Wedding Ringer</title>
        <duration> 100 mins </duration>
    <movie id="1003">
        <title>The Avengers</title>
        <duration> 180 mins </duration>   
    <movie id="1004">
        <title>Taken 3</title>
        <duration> 100 mins </duration>

    <movie id="1005">
        <genre>Science Fiction</genre>
        <duration>180 mins</duration>

    <movie id="1006">
        <title>Jurassic World</title>
        <duration>120 mins</duration>

    <movie id="1007">
        <genre>Science Fiction</genre>
        <duration>180 mins</duration>

for example client key in "Interstellar" and the server will receive and get the id value. now my problem is i only can print out the movie id and title only. i need to print out the whole set thing, example, movie id,title, genre and duration. do i need loop for that?

Here's one way:
System.out.println("title = " + movie.getElementsByTagName("title").item(0).getTextContent());

thanks for the help, its working.
This question has already been answered. Start a new discussion instead.