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

ValidationTest

public class ValidationTest extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.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();
        }