ArrayOfAddresses lista = new ArrayOfAddresses(); Address a1 = new Address(); a1.setCity("Thiene"); a1.setCountry("Italia"); a1.setStreet("via dei Tigli"); Point p1 = new Point(); p1.setLatitude(44.4566); p1.setLongitude(10.4677); a1.setLocation(p1); lista.Add(a1); Address a2 = new Address(); a2.setCity("Schio"); a2.setCountry("Italia"); a2.setStreet("via Tito Livio"); Point p2 = new Point(); p2.setLatitude(45.1548); p2.setLongitude(9.5677); a2.setLocation(p2); lista.Add(a2); JAXBContext context1 = JAXBContext.newInstance(ArrayOfAddresses.class); Marshaller marshaller1 = context1.createMarshaller(); marshaller1.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); DocumentBuilderFactory dbf1 = DocumentBuilderFactory.newInstance(); dbf1.setNamespaceAware(true); DocumentBuilder db1 = dbf1.newDocumentBuilder(); Document doc1 = db1.newDocument(); marshaller1.marshal(lista, doc1); marshaller1.marshal(lista, System.out); // DEBUG -- stampa su console output
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>Thiene Italia 0 44.4566 10.4677 via dei Tigli Schio Italia 0 45.1548 9.5677 via Tito Livio