2012-01-03 33 views
0

我有這樣的XML保存在我的projecy(文件夾/ xml.xml)離線閱讀XML:無法在Windows Phone的

<?xml version="1.0" encoding="utf-8"?> 
    <myxml> 
    <table name="dati"> 
     <column name="Ordine">1</column> 
     <column name="Data">07/11/2011</column> 
     <column name="Nome_Comico">Massimo</column> 
     <column name="Frase">ciao ciao</column> 
     <column name="Descrizione">ola ola</column> 
     <column name="URL_img">foto.png</column> 
    </table> 
    <table name="dati"> 
     <column name="Ordine">1</column> 
     <column name="Data">07/11/2011</column> 
     <column name="Nome_Comico">Massimo</column> 
     <column name="Frase">ciao ciao</column> 
     <column name="Descrizione">ola ola</column> 
     <column name="URL_img">foto.png</column> 
    </table> 
    </myxml> 

我現在的代碼是:

public ComiciPage() 
    { 
     if (InternetIsAvailable()) 
     { 
      InitializeComponent(); 
      var xdoc = XDocument.Load("folder/xml.xml"); 
      var result = from o in xdoc.Document.Descendants("table") 
      select new myObject(o.Element("Nome_Comico").Value,o.Element("Nata").Value,o.Element("Ordine").Value); 
      Debug.WriteLine(result.ToList<myObject>()); 
     } 
     else 
     { 
      NavigationService.Navigate(new Uri("/MyApp;component/App.xaml", UriKind.Relative)); 
     } 
    } 
    public class myObject 
    { 
     public string Property1 { get; set; } 
     public string Property2 { get; set; } 
     public string Property3 { get; set; } 
     public myObject(string _property1, string _property2, string _property3) 
     { 
      this.Property1 = _property1; 
      this.Property1 = _property1; 
      this.Property1 = _property1; 
     } 
    } 

問題是我不能讀它。我學會了如何解析一個在線XML,但一個簡單的,一些離線教程...但我不能讀它,因爲我有那個奇怪的節點... 有人可以幫助我嗎? 現在,我只需要把這些值,並將其放在調試,只是爲了看到工作,我會用它之後。

謝謝大家

+0

在doucment你'Nome_Comico'但在讀碼這是編輯'nome' – Ku6opr 2012-01-03 13:49:24

+0

。但這不是問題所在。 任何人都可以幫助我? – Zak 2012-01-04 13:23:40

回答

0

我覺得錯誤是錯誤的相對路徑。如果您不忘記在項目中爲其設置屬性「內容」,您可以嘗試打開存儲在獨立存儲中的文件作爲流。然後,你應該使用方法,需要流對象作爲參數,而不是文件路徑:

 
using (var appStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
using (var file = appStorage.OpenFile("folder/xml.xml", FileMode.Open)) 
{ 
    XElement.Load(file); 
} 
+0

但之後,我發現這個錯誤: var result = from xdoc.Document.Descendants(「table」) on xdoc – Zak 2012-01-05 10:11:45

相關問題