public static void writeXML() throws Exception {

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();

        Document highScoreListe = builder.newDocument();

        Element root = highScoreListe.createElement("root");

        for (SlidingPuzzleHighscore thisScore : puzzleHighscores) {

            Element userElement = highScoreListe.createElement("user");

            userElement.setAttribute("name", thisScore.getUserName());
            userElement.setAttribute("score", thisScore.getUserScore());

            root.appendChild(userElement);
        }

        highScoreListe.appendChild(root);

        DOMSource source = new DOMSource(highScoreListe);

        PrintStream ps = new PrintStream("highscore.xml");
        StreamResult result = new StreamResult(ps);

        TransformerFactory transformerFactory = TransformerFactory
                .newInstance();
        Transformer transformer = transformerFactory.newTransformer();

        transformer.transform(source, result);
    }