繁体   English   中英

将XML文件加载到ecore模型中(反序列化)

[英]Loading XML file into ecore model (Deserialisation)

这真的让我感到紧张...

我已经启动并运行了所有ecore模型,但是无法将XML文件加载到这些模型中,这是我正在使用的代码:

        ResultType res = ScheduleTableFactory.eINSTANCE.createResultType(); 
    ByteArrayInputStream is;

    try {

        /* Read XML file to a string and send it to a buffer */
        is = new ByteArrayInputStream((this.xml2String(fileName)).getBytes("UTF-8"));

        ResourceSet rs = new ResourceSetImpl();
        rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", 
        new ScheduleTableResourceFactoryImpl());

        Map options = new Properties();

        // Just a dummy url to specify the type of the document
        URI uri = URI.createURI("http://www.baderous.de/doomz/trankz.xml");
        ScheduleTableResourceImpl resource = (ScheduleTableResourceImpl) rs.createResource(uri);    

        ((org.eclipse.emf.ecore.resource.Resource) resource).load(is, options);
    }
    catch (IOException e) {

        e.printStackTrace();
        System.exit(0);
    }

经过长时间的努力,现在到达了try块中的最后一个方法,但这给了我这个错误:

org.eclipse.emf.ecore.resource.Resource $ IOWrappedException:值'2013-04-23.07:55:00'不合法。 http://www.baderous.de/doomz/trankz.xml,4,56

我希望在此描述中更加精确,但是我对EMF还是很陌生,因此我只会坚持基础知识。 如果您能在这个问题上帮助我,我将不胜感激。

提前致谢!

尝试将值'2013-04-23.07:55:00'括在块CDATA中

问题是日期格式无法处理,因此我不得不在EMf中编辑模型,现在我将日期视为字符串,现在一切正常!

希望将来有人可以从此答案中受益,并节省一些时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM