【问题标题】:How to generate Castor mapping.xml file from given multiple XSDs?如何从给定的多个 XSD 生成 Castor mapping.xml 文件?
【发布时间】:2011-01-19 15:26:00
【问题描述】:

如何从给定的多个 XSD 生成 Castor mapping.xml 文件?

【问题讨论】:

    标签: xsd mapping castor


    【解决方案1】:

    导入 java.io.FileNotFoundException; 导入 java.io.FileOutputStream; 导入 java.io.OutputStream; 导入 java.io.OutputStreamWriter; 导入 java.io.Writer;

    //import org.exolab.castor.builder.SourceGenerator; 导入 org.exolab.castor.mapping.MappingException; 导入 org.exolab.castor.tools.MappingTool;

    公共类 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();
        }
    }
    

    }

    【讨论】:

    • Castor-0.9.5.4 版本支持这个吗?我在那里找不到BackwardCompatibilityContext 类。
    • 嗨 tamerrab,你是如何在这里输入你的 xsd 来生成 mapping.xml 文件的?上面的代码只生成了一个两行存根。这是我关于该主题的类似帖子,但尚未找到任何解决方案:stackoverflow.com/questions/27426218/…
    猜你喜欢
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多