public void demoWrite() {
try {
ObjectFactory factory = new ObjectFactory();
PurchaseOrders orders = factory.createPurchaseOrders();
// Order 1
PurchaseOrder order = factory.createPurchaseOrder();
USAddress billTo = factory.createUSAddress();
billTo.setCity("Cambridge");
billTo.setCountry("US");
billTo.setName("Robert Smith");
billTo.setState("MA");
billTo.setStreet("8 Oak Avenue");
billTo.setZip(new BigDecimal(12345));
order.setBillTo(billTo);
USAddress shipTo = factory.createUSAddress();
shipTo.setCity("Cambridge");
shipTo.setCountry("US");
shipTo.setName("Alice Smith");
shipTo.setState("MA");
shipTo.setStreet("123 Maple Street");
shipTo.setZip(new BigDecimal(12345));
order.setShipTo(shipTo);
Calendar orderDate = Calendar.getInstance();
orderDate.set(2004, 06, 30);
order.setOrderDate(orderDate);
Items items = factory.createItems();
order.setItems(items);
orders.getPurchaseOrder().add(order);
// Order 2
PurchaseOrder order2 = factory.createPurchaseOrder();
USAddress billTo2 = factory.createUSAddress();
billTo2.setCity("Cambridge");
billTo2.setCountry("US");
billTo2.setName("Robert Smith");
billTo2.setState("MA");
billTo2.setStreet("8 Oak Avenue");
billTo2.setZip(new BigDecimal(12345));
order2.setBillTo(billTo2);
USAddress shipTo2 = factory.createUSAddress();
shipTo2.setCity("Cambridge");
shipTo2.setCountry("US");
shipTo2.setName("Alice Smith");
shipTo2.setState("MA");
shipTo2.setStreet("123 Maple Street");
shipTo2.setZip(new BigDecimal(12345));
order2.setShipTo(shipTo2);
Calendar orderDate2 = Calendar.getInstance();
orderDate2.set(2004, 06, 30);
order2.setOrderDate(orderDate2);
Items items2 = factory.createItems();
order2.setItems(items2);
orders.getPurchaseOrder().add(order2);
File outputFile = new File(outputDir, "jaxbWrite.xml");
JAXBWriter jaxbWriter = new JAXBWriter("org.dom4j.test.primer",
OutputFormat.createPrettyPrint());