我有以下XML:.NET XML反序列化有着不同的價值觀
<results>
<row>
<id>4990321</id>
<field name="First name">John</field>
<field name="Last name">Snow</field>
<field name="Country">USA</field>
<field name="City">San-Diego</field>
<field name="Postcode">123456</field>
<field name="Email">[email protected]</field>
<field name="Message">Hello</field>
</row>
<row>
...
<row>
</results>
我需要反序列化的對象數組:
public class Employee
{
public string Id { set; get; }
public string Firstname { set; get; }
public string Lastname { set; get; }
public string Country { set; get; }
public string City { set; get; }
public string Postcode { set; get; }
public string Email { set; get; }
public string Message { set; get; }
}
我試着使用來實現它XmlElementAttribute
和XmlAttributeAttribute
,但屬性名爲ElementName
不理解XPath,所以我無法獲得特定字段的值(如field[name='Email']
)
誰有什麼想法我該怎麼做?不需要XDocument解析。
你有沒有嘗試過這樣的事情?:https://msdn.microsoft.com/en-us/library/bb387041.aspx – montewhizdoh
@montewhizdoh使用LINQ我需要解析它。我在文章的最後寫道,我想避免XElement/XDocument。這對我的任務來說非常沉重。 – matterai