Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8962311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:06:02+00:00 2026-06-15T16:06:02+00:00

I am still new in programming and would appreciate if anyone can help me

  • 0

I am still new in programming and would appreciate if anyone can help me out on this one, basically I have a movie file that I want to unmarshall and with only “Robert Benton” person/director as an output on system.out.

Java class with JAXBU

        package jaxbadv;

    import java.io.File;
    import java.util.Iterator;
    import java.util.List;

    import org.me.media.*;
    /**
     *
     * @author Ket
     */
    public class rbFilms {

    public static void main(String[] args) {
        // Create root XML node 'todaysShow' and get its main element 'movies_today'
        ShowingToday todaysShow = new ShowingToday();
        List<MovieType> movies_today =  todaysShow.getMovieCollection();
        // Create Movie instanses and add them to the 'movies_today' collection
        MovieType film;


        film = new MovieType();
        film.getTitle();
        film.getDirector();
        film.getYear();

        try {
            javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(film.getClass().getPackage().getName());
            javax.xml.bind.Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
            film = (MovieType) unmarshaller.unmarshal(new java.io.File("Now_Showing.txt")); //NOI18N

            //print out only movies produced after 1990
            MovieType nextMovie = new MovieType();
            Iterator itr = movies_today.iterator();
            while(itr.hasNext()) {
                nextMovie = (MovieType) itr.next();
                if(nextMovie.getDirector() == "Robert Benton") {
                    System.out.println(nextMovie.getTitle());
                }
            }


        } catch (javax.xml.bind.JAXBException ex) {
            // XXXTODO Handle exception
            java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex); //NOI18N
        }




    }
}

XML file

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Showing_Today xmlns="http://xml.netbeans.org/schema/Shows">
    <movie_collection>
        <Title>Red</Title>
        <Director>Robert Schwentke</Director>
        <Year>2010</Year>
    </movie_collection>
    <movie_collection>
        <Title>Kramer vs Kramer</Title>
        <Director>Robert Benton</Director>
        <Year>1979</Year>
    </movie_collection>
    <movie_collection>
        <Title>La Femme Nikita</Title>
        <Director>Luc Besson</Director>
        <Year>1997</Year>
    </movie_collection>
    <movie_collection>
        <Title>Feast of love</Title>
        <Director>Robert Benton</Director>
        <Year>2007</Year>
    </movie_collection>
</Showing_Today>

JAXB Binding generated source – ShowingToday

    package org.me.media;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "movieCollection"
})
@XmlRootElement(name = "Showing_Today")
public class ShowingToday {

    @XmlElement(name = "movie_collection")
    protected List<MovieType> movieCollection;

public List<MovieType> getMovieCollection() {
        if (movieCollection == null) {
            movieCollection = new ArrayList<MovieType>();
        }
        return this.movieCollection;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:06:03+00:00Added an answer on June 15, 2026 at 4:06 pm

    You might want to start with some simpler exercise, there are some basic Java mistakes you are making in your code. For example, you have some no-effect assignments:

    showingToday todaysShow = new ShowingToday(); // value isn't used
    List<MovieType> movies_today =  todaysShow.getMovieCollection(); // value isn't used
    

    And some places you are initializing a variable and making no-effect get calls on it:

    film = new MovieType(); // values is never used
    film.getTitle();        // this and the other get calls are not needed
    film.getDirector();
    film.getYear();
    

    You will want to fix these.


    As far as your particular JAXB problem, from what I can tell, you should be deserializing a ShowingToday instance from your XML stream, and then accessing information from it. Code would be similar to this:

    try {
       final JAXBContext context = JAXBContext
             .newInstance(ShowingToday.class);
       final Unmarshaller unmarshaller = context.createUnmarshaller();
       final ShowingToday showingToday = unmarshaller.unmarshal(
             new StreamSource(new File("absolute path of file here")),
             ShowingToday.class).getValue();
    
    } catch (final Exception e) {
       // Do something useful here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Help me brainstorm how I would solve this problem. I have a file of
I'm still new to the Ada programming world so forgive me if this question
I'm still pretty new to programming so I have somewhat of a noob question.
Yes I have seen This question But it's for php. I'm still new to
I'm still new to programming/Java/Android so I'm trying to understand everything I do and
I'm still very new at programming, and our local SSIS genius isn't here today
Hi I am still pretty new to programming and I haven't had the chance
I'm still relatively new to C++ and programming, but having a good time learning.
First, i'm new at Java-programming and my native lang is not english, but still
still new to XML parsing with the iphone so i have a few questions.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.