if (args.length != 1) {
System.out.println("Usage: java javajaxb.ValidationTest2 " +
"[XML movie database filename]");
return;
}
try {
File xmlFile = new File(args[0]);
FileInputStream inputStream = new FileInputStream(xmlFile);
// Read in movies database
Movies movies = Movies.unmarshal(inputStream);
/* ******* SETTING INVALID DATA *********** */
List movieList = movies.getMovie();
Movie movie = (Movie)movieList.get(0);
Cast cast = movie.getCast();
List actorList = cast.getActor();
Actor actor = (Actor)actorList.get(0);
actor.setHeadliner("illegalValue");
// 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();
}