2012-02-27 77 views
-1

我用下面的代碼:在Windows Phone中解析xml?

var data = from query in loadedData.Descendants("chapter") 
        select new CountryData 
        { 
         Title = (string)query.Element("title"), 
         data1 = from pharagraph in loadedData.Descendants("pharagraph") 
           select new CountryData 
           { 
            Title1=(string)pharagraph.Element("title"), 
            Des = (string)pharagraph.Element("text"), 
            Position = (int)pharagraph.Element("position"), 
           } 
        }; 
     countryList = data.ToList(); 

顯示標題1 value.how時顯示在XML reader.my xml文件內的標題標記看起來像我有錯誤:HTTP://stackoverflow.com/questions/9431276/讀動態XML閱讀器換窗戶電話

回答

1

大概從loadedData選擇pharagraph不是:

data1 = from pharagraph in loadedData.Descendants("pharagraph") 

但從pharagraphs元素(或類似的東西取決於你的XML):

data1 = from pharagraph in (query.Element("pharagraphs")).Descendants("pharagraph") 

高級代碼:

var data = from query in loadedData.Descendants("chapter") 
       select new CountryData 
       { 
        Title = (string)query.Element("title"), 
        data1 = (from pharagraph in (query.Element("pharagraphs")).Descendants("pharagraph") 
          select new CountryData 
          { 
           Title1=(string)pharagraph.Element("title"), 
           Des = (string)pharagraph.Element("text"), 
           Position = (int)pharagraph.Element("position"), 
          }).ToList() 
       }; 
    countryList = data.ToList(); 
+0

但我使用上述code.please explain.please給出一些示例代碼來解析像上面的XML數據時有差錯。 – Malarkodi 2012-02-27 11:46:17

+0

更新了我的答案。投射到'string'是不需要的。另外,我添加了ToList()。希望這會有所幫助 – Ku6opr 2012-02-27 11:53:20

+0

非常感謝。當我將Title1值綁定到文本塊中時,我的error.sorry是新手機windows.i沒有指導在我的位置。 – Malarkodi 2012-02-27 12:01:51