例子的數據存儲的子節點:LINQ/XML - 它有一個自定義的類不同的名字
<property>
<price>2080000</price>
<country>France</country>
<currency>euro</currency>
<locations>
<location_9>Ski</location_9>
<location_16>50km or less to airport</location_16>
<location_17>0-2KM to amenities</location_17>
</locations>
<secondaryproptypes>
<secondaryproptypes_1>Holiday Home</secondaryproptypes_1>
</secondaryproptypes>
<features>
<features_30>Woodburner(s)</features_30>
<features_9>Private parking</features_9>
<features_23>Mountain view</features_23>
<features_2>Mains Drains</features_2>
</features>
的例子物業類別:
public class Property
{
public decimal price { get; set; }
public string country { get; set; }
public string currency { get; set; }
public List<Location> locations { get; set; }
}
位置的示例類:
public class Location
{
public string location { get; set; }
}
主代碼:(也嘗試了很多衍生物,但是當我放棄時,它就是這樣)
public void LoadXMLURL()
{
XDocument document = XDocument.Load("file.xml");
var properties = (from p in document.Root.Elements("property")
select new Property
{
price = Convert.ToDecimal(p.Element("price").Value),
country = p.Element("country").Value,
currency = p.Element("currency").Value,
locations = new List<Location>(from l in p.Descendants("location")
select new Location
{
location = (string)l
})
}
).ToList();
我曾嘗試過多種存儲位置數據節點列表的方法。如數組和其他列表。
現在我認爲我的主要問題是,因爲節點是不同的; 「location_9」 「location_16」
我無法指定要查看的節點,與我以前的節點一樣嚴格。
代替''使用類似'<位置ID =「9」>' –
我有超過的XML的格式沒有控制,對不起,我應該指定此。 – Birksy89