public static void main(String[] args) {

        try {

        SAXBuilder saxBuilder = new SAXBuilder();

       File file = new File("D:\\Java SE\\src\\xml\\jdom\\file.xml");

            Document document = (Document)saxBuilder.build(file);

            Element node =  document.getRootElement();

            Element staff = node.getChild("staff");

            staff.getAttribute("id").setValue("4");

            Element element = new Element("age").setName("personage").setText("28");

            staff.addContent(element);

            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 updated!");
        } catch (IOException io) {
            io.printStackTrace();
        } catch (JDOMException e) {
            e.printStackTrace();
        }
    }