简体   繁体   English

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

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

This is really getting into my nerve... 这真的让我感到紧张...

I already have all the ecore models up and running but I've been unable to load an XML file into those models.This is the code I'm using to do so: 我已经启动并运行了所有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);
    }

After a long struggle, now it's reaching the last method inside the try block, but it's giving me this error: 经过长时间的努力,现在到达了try块中的最后一个方法,但这给了我这个错误:

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

I wanted to be more precise in this description, but I'm quite new with EMF, so I will just stick to the basics. 我希望在此描述中更加精确,但是我对EMF还是很陌生,因此我只会坚持基础知识。 I would be really grateful if you can help me on this issue. 如果您能在这个问题上帮助我,我将不胜感激。

Thanks in advance! 提前致谢!

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

The problem was that the date format couldn't be handled, so I had to edit the model in EMf, and now I'm treating dates as Strings.And now everything is working properly! 问题是日期格式无法处理,因此我不得不在EMf中编辑模型,现在我将日期视为字符串,现在一切正常!

Hope that in the future someone can benefit from this answer, and save some time. 希望将来有人可以从此答案中受益,并节省一些时间。

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

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