2012-07-27 45 views
1

我試圖根據Handling XML files on Windows PhoneXML反序列

的XML文件進行反序列化在Windows Phone上的XML文件類似於這樣

<positions> 
<POS LAT=12312312 LON=23113123\> 
</positions> 

在C#中,我使用,

[XMLRoot("positions")] 
public class Positions  
{ 
[XmlArray] //These two lines seem to be where the problem is... 
[XmlArrayItem("POS")] 
public ObservableCollection<POS> Collection {get;set;} 
} 

類POS.cs看起來像

public class POS.cs 
{ 
[XMLAttribute("LAT")] 
public string LAT{get;set;} 

[XmlArray(「FOO」)]和[XmlArrayItem(「BAR」)]應該是什麼樣子? 東西在這裏不能正常工作... 感謝您的幫助!

回答

1

XmlArray/XmlArrayItem適用於需要雙層層次結構的位置;在你的情況下,POSpositions直接孩子,所以XmlElement是正確的佈局:

[XmlRoot("positions")] 
public class Positions  
{ 
    [XmlElement("POS")] 
    public ObservableCollection<POS> Collection {get;set;} 
} 
+0

+1,剛修好'[XMLRoot( 「位置」)]'這應該是'[XmlRoot( 「陣地」 )]和'[Element(「POS」)]'應該是'[XmlElement(「POS」)]'。 – 2012-07-27 08:01:06

+0

@Darin夠公平的;第一個是從問題中複製/粘貼;第二個是我自己的粗心 – 2012-07-27 08:05:24