问题
How to generate Castor mapping.xml file from given multiple XSDs?
回答1:
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer;
//import org.exolab.castor.builder.SourceGenerator; import org.exolab.castor.mapping.MappingException; import org.exolab.castor.tools.MappingTool;
public class CastorMappingToolUtil {
public static void generate() throws MappingException, FileNotFoundException {
MappingTool tool = new MappingTool();
tool.setInternalContext(new org.castor.xml.BackwardCompatibilityContext());
tool.addClass(ClassType.class);
OutputStream file = new FileOutputStream("/path/to/xmlFile/gen_mapping.xml" );
Writer writer = new OutputStreamWriter(file);
tool.write(writer);
//SourceGenerator.main(options);
}
/**
* @param args
*/
public static void main(String[] args) {
try {
CastorMappingToolUtil.generate();
} catch (MappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
来源:https://stackoverflow.com/questions/4737063/how-to-generate-castor-mapping-xml-file-from-given-multiple-xsds