import java.io.*;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.types.GYear;
import OOP2002Example.*;

public class example4
{
   public static void main(String[] argv)
   {
	   try
	   {
	      Pkw myPkw = Pkw.unmarshal(new FileReader( argv[0] ));

	      //creating an attribute
	      myPkw.setBaujahr( new GYear(2002) );

         //creating an element (somewhat complicated due to XML schema's structure)
         Rad myNewRad = new Rad();
         RadTypeItem myRadTypeItem = new RadTypeItem();
         myRadTypeItem.setRad ( myNewRad );
         myPkw.getRaeder().addRadTypeItem( myRadTypeItem );

         //creating an element (the normal way ;)
         myPkw.setHalter( "John Doe" );

         //write modified XML file
         myPkw.marshal(new FileWriter(argv[1]));
      } //try
      catch (MarshalException e)
      {
         Exception originatingException = e.getException();
         if (originatingException != null)
         {
            System.out.println(originatingException);
         } //if
      } //catch
      catch (Exception e)
      {
         System.out.println("EXCEPTION: "+e);
      }
   } //main()
} //class example4