import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import org.w3c.dom.*; import java.io.*; public class UusDokument2{ public static void main(String argumendid[]) throws Exception{ BufferedReader sisse=new BufferedReader( new InputStreamReader(System.in)); Document d=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element juur=d.createElement("linnad"); d.appendChild(juur); System.out.println("Palun linn:"); String linnanimi=sisse.readLine(); while(linnanimi.length()>0){ Element e=d.createElement("linn"); e.appendChild(d.createTextNode(linnanimi)); juur.appendChild(e); System.out.println("Palun linn:"); linnanimi=sisse.readLine(); } Transformer t=TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(d), new StreamResult(System.out)); } }