FileDocCategorySizeDatePackage
ValidationTest.javaAPI DocExample1550Sun Jul 07 09:49:38 BST 2002javajaxb

ValidationTest.java

package javajaxb;

import java.io.File;
import java.io.FileOutputStream;

// Generated Classes
import javajaxb.generated.movies.*;

public class ValidationTest {

    public static void main(String[] args) {
        try {
            // Create a movie database
            Movies movies = new Movies();
            // version attribute NOT set

            /** Add this line in to fix the validation error
            // Validate
            movies.validate();
            */

            // Create a new movie
            Movie movie = new Movie();
            movie.setTitle("Attack of the Clones");
            movie.setDirector("George Lucas");
            movie.getProducer().add("Rick McCallum");
            movies.getMovie().add(movie);

            // Set cast
            Cast cast = new Cast();
            Actor obiwan = new Actor();
            obiwan.setContent("Ewan McGregor");
            obiwan.setHeadliner("true");
            cast.getActor().add(obiwan);

            Actor anakin = new Actor();
            anakin.setContent("Hayden Christensen");
            anakin.setHeadliner("true");
            cast.getActor().add(anakin);
            movie.setCast(cast);

            // Create output stream
            File file = new File("output.xml");
            FileOutputStream outputStream = new FileOutputStream(file);

            // Marshal back out
            movies.marshal(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}