public static void main(String[] args) {

        try {

            Element company = new Element("company");

            Document document = new Document();

            document.setRootElement(company);


            Element staff = new Element("staff");

            staff.addContent(new Element("name").setText("Sergii"));

            staff.addContent(new Element("age").setText("25"));

            staff.addContent(new Element("language").setText("UKR"));


            document.getRootElement().addContent(staff);


            // new XMLOutputter().output(doc, System.out);
         XMLOutputter xmlOutputter = new XMLOutputter();

            xmlOutputter.setFormat(Format.getPrettyFormat());
            xmlOutputter.output(document, new FileWriter("D:\\Java SE\\src\\xml\\jdom\\file.xml"));

            System.out.println("File Saved!");
        } catch (IOException io) {
            System.out.println(io.getMessage());
        }
    }