I have programmatically created a XML File in Java with the JDom2 library. When I try to import that file into MS Project, I get an error (We're sorry but it seems that ther is a problem in this file that doesn't allow us to open. Try to use a backup if available)
But when i copy the content of the XML file, in a new file and save it as XML, when I try to import it in Project works perfectly.
Why is this possible, and how can I solve it?
Edit: to put some code
Element e = new Element("Project");
Document doc = new Document(e);
e.addContent(new Element("SaveVersion").setText("14"));
e.addContent(new Element("Name").setText(nomFichero));
e.addContent(new Element("CreationDate").setText(fecha));
e.addContent(new Element("LastSaved").setText(fecha2));
e.addContent(new Element("ScheduleFromStart").setText("1"));
e.addContent(new Element("StartDate").setText(fecha));
e.addContent(new Element("FinishDate").setText(fecha));
e.addContent(new Element("FYStartDate").setText("1"));
e.addContent(new Element("CriticalSlackLimit").setText("0"));
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat());
xmlOutput.output(doc, new FileWriter(file));
Maybe it is file encoding issue - the two files (one generated and one created manually) have different encoding. The first one is incorrect and the second one is correct.
If that's the case, you should generate file with the right encoding. You could try:
Of course you should use encoding that suits your needs (perhaps
Charset.defaultCharset()
will work).