How To: Convert project data from one format to another

To convert project data between different formats you read the source data using an appropriate Reader class, the write the data using a Writer class which matches the format you want to convert to.

MPXJ can do a lot of the work for you, as the example below illustrates. This example works where you have source and target file formats which can be easily recognised by the file extension (for example .mpp, .mpx, .xer, and so on)

import net.sf.mpxj.ProjectFile;
import net.sf.mpxj.reader.ProjectReader;
import net.sf.mpxj.reader.ProjectReaderUtility;
import net.sf.mpxj.writer.ProjectWriter;
import net.sf.mpxj.writer.ProjectWriterUtility;

...

ProjectReader reader = ProjectReaderUtility.getProjectReader(inputFile);
ProjectFile projectFile = reader.read(inputFile);

ProjectWriter writer = ProjectWriterUtility.getProjectWriter(outputFile);
writer.write(projectFile, outputFile);

If you already know the file types you are converting between, you can use the specific Reader and Writer classes, as shown below.

import net.sf.mpxj.ProjectFile;
import net.sf.mpxj.reader.ProjectReader;
import net.sf.mpxj.writer.ProjectWriter;
import net.sf.mpxj.mpp.MPPReader;
import net.sf.mpxj.mpx.MPXWriter;
...

ProjectReader reader = new MPPReader();
ProjectFile projectFile = reader.read(inputFile);

ProjectWriter writer = new MPXWriter();
writer.write(projectFile, outputFile);

The following conversions are possible using MPXJ:

To
From MPP MPX MSPDI Planner XER PM XML SDEF Asta
MPP yes yes yes yes yes
MPX yes yes yes yes yes
MSPDI yes yes yes yes yes
Planner yes yes yes yes yes
XER yes yes yes yes yes
PM XML yes yes yes yes yes
SDEF
Asta yes yes yes yes yes