【发布时间】:2017-12-20 21:06:05
【问题描述】:
有没有办法将 XmlElements 反序列化为嵌套的复杂对象。我试图让 URL、用户名和密码填充 ServiceProvider.Properties 对象。目前所有的值都是空的。
public class ServiceProvider
{
[XmlElement("ID")]
public SettingId SettingId { get; set; }
public Properties Properties { get; set; }
}
public class Properties
{
[XmlElement]
public string Username { get; set; }
[XmlElement]
public string URL { get; set; }
[XmlElement]
public string Password { get; set; }
}
public class SettingId
{
[XmlElement]
public string Key { get; set; }
[XmlElement]
public string Domain { get; set; }
[XmlElement]
public string Type { get; set; }
}
<ServiceProviders>
<ServiceProvider>
<ID>
<Key>Key</Key>
<Domain>Domain</Domain>
<Type>Type</Type>
<ID>
<URL>URL</URL>
<Username>User</Username>
<Password>Password</Password>
</ServiceProvider>
</ServiceProviders>
【问题讨论】:
-
感谢您的重播,但这就是我现在对其进行编码的方式,并且属性对象中的值为 null。
-
您的 XML 无效。顺便说一句
</ID>
标签: c# xml deserialization