public static void createXml(List<WordWithCount> sortedList, Writer outputWriter, int maxListSize) throws IOException {
        final int wordsCount = Math.min(maxListSize, sortedList.size());

        XmlWriter writer = new XmlWriter(outputWriter, false, 0, true);
        writer.writeEntity("wordlist");
        for (int wordIndex = 0; wordIndex < wordsCount; wordIndex++) {
            WordWithCount word = sortedList.get(wordIndex);
            writer.writeEntity("w").writeAttribute("f", Integer.toString(calcActualFreq(wordIndex, wordsCount))).writeText(word.getWord()).endEntity();
        }
        System.out.println("Wrote " + wordsCount + " words.");
        writer.endEntity();
    }