import org.jdom.Element;
import org.jdom.DocType;
import org.jdom.Document;
import org.jdom.Comment;
import org.jdom.output.XMLOutputter;
import java.io.IOException;

public class MujXML {
 public static void main(String[] args) throws IOException {
  //root tag, napr. HTML
  Element rootElement = new Element("hlavnitag");
  //DTD definice dokumentu
  DocType doctype = new DocType("hlavnitag","definice.dtd");
  //prazdny dokument
  Document doc = new Document(rootElement,doctype);
  //obsah dokumentu
  rootElement.addAttribute("mujatribut","1");
  rootElement.addContent(new Comment(" komentar "));
  rootElement.addContent( (new Element("podrizenytag")).addContent("obsah"));
  Element seznam = new Element("seznam");
  rootElement.addContent(seznam);
  for(int i = 1; i<10;i++) {
            Element polozka = new Element("polozka");
            seznam.addContent(polozka);
            polozka
            .addAttribute("id",Integer.toString(i))
            .addAttribute("jmeno","AAA"+i)
            .addAttribute("cislo",Integer.toString(i*i))
            ;
        }
  //vytisknuti
  XMLOutputter fmt = new XMLOutputter(" ",true,"ISO-8859-1");
  fmt.output(doc, System.out);
 }
}

