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 Linnad2{ public static void main(String argumendid[]) throws Exception{ BufferedReader klaver=new BufferedReader(new InputStreamReader(System.in)); Document d=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element juur=d.createElement("linnad"); d.appendChild(juur); System.out.println("Palun linna nimi"); String linnanimi=klaver.readLine(); do{ Element e=d.createElement("linn"); e.appendChild(d.createTextNode(linnanimi)); juur.appendChild(e); System.out.println("Palun linna nimi"); linnanimi=klaver.readLine(); } while(linnanimi.length()>0); Transformer t=TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(d), new StreamResult(new FileOutputStream("linnad.xml"))); } }