1  import java.util.ArrayList;
  2  import org.w3c.dom.DOMImplementation;
  3  import org.w3c.dom.Document;
  4  import org.w3c.dom.ls.DOMImplementationLS;
  5  import org.w3c.dom.ls.LSSerializer;
  6  
  7  /**
  8     This program demonstrates the item list builder. It prints the XML 
  9     file corresponding to a DOM document containing a list of items.
 10  */
 11  public class ItemListBuilderDemo
 12  {
 13     public static void main(String[] args) throws Exception
 14     {
 15        ArrayList<LineItem> items = new ArrayList<LineItem>();
 16        items.add(new LineItem(new Product("Toaster", 29.95), 3));
 17        items.add(new LineItem(new Product("Hair dryer", 24.95), 1));
 18  
 19        ItemListBuilder builder = new ItemListBuilder();
 20        Document doc = builder.build(items);         
 21        DOMImplementation impl = doc.getImplementation();
 22        DOMImplementationLS implLS 
 23              = (DOMImplementationLS) impl.getFeature("LS", "3.0");
 24        LSSerializer ser = implLS.createLSSerializer();
 25        String out = ser.writeToString(doc);      
 26        
 27        System.out.println(out);
 28     }
 29  }