Prubuje zrobić zrzut struktury plików do xml-a od podanej lokalizacji

<dokumenty size="700"> <ulubione size="500"> <plik_txt size="500" /> </ulubione> <plik_txt size="200" /> </dokumenty>

Jadnakże z tego co wyczytałem xml ma pewne ograniczenia np. nie może być spacji, kropek itd. Co proponujecie ? może regex?

Error: http://prntscr.com/almte4

public class DOM {

    private static Document xmldoc;

    static void recursiveList(File currentFile, Element parent) {
        File[] listOfFiles = currentFile.listFiles();

        for (File aFile : listOfFiles) {

            Element e = xmldoc.createElementNS(null, aFile.getName());

            long filesize = aFile.length();

            e.setAttributeNS(null, "size", String.valueOf(filesize));

            parent.appendChild(e);
            if (aFile.isDirectory()) {
                recursiveList(aFile, e);
            }
        }
    }

    public static void main(String[] args) throws IOException {

        File startingDirectory = new File("C:\\Baza danych");

        xmldoc = new DocumentImpl();
        String path = startingDirectory.getName().replaceAll("[\\W.]", "_");
        
        System.out.println(path);
        Element root = xmldoc.createElement(path);
        recursiveList(startingDirectory, root);
        xmldoc.appendChild(root);

        FileOutputStream fos = new FileOutputStream("file.xml");

        OutputFormat of = new OutputFormat("XML", "ISO-8859-1", true);
        of.setIndent(1);
        of.setIndenting(true);
        XMLSerializer serializer = new XMLSerializer(fos, of);

        serializer.asDOMSerializer();
        serializer.serialize(xmldoc.getDocumentElement());
        fos.close();

    }

}