2014-03-07 31 views
1

這是真正把我的神經......加載XML文件轉換成Ecore模型(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頗爲新穎,所以我只會堅持基礎知識。如果你能在這個問題上幫助我,我將非常感激。

在此先感謝!

回答

0

問題是日期格式無法處理,所以我不得不在EMf中編輯模型,現在我將日期視爲字符串。現在一切工作正常!

希望將來有人可以從這個答案中受益,並節省一些時間。

1

嘗試在塊CDATA中包含值'2013-04-23.07:55:00'。

+0

謝謝,但它沒有奏效。它給了我完全相同的錯誤:org.eclipse.emf.ecore.resource.Resource $ IOWrappedException:Value'![CDATA [2013-357T07:55:00]]''是不合法的。 (http://www.baderous.de/doomz/trankz.xml,4,66) – rsy

+0

請發佈一些XML代碼的和平與這個不好的價值。 – DmitryKanunnikoff

+0

不過,你的回答讓我明白,我遇到的問題只是在閱讀日期!謝謝!我將使用xml代碼編輯最初的帖子 – rsy