我想序列化一个对象,其中一个属性映射到2个xml元素。我正在通过其RESTful API创建一个与wifi帐户管理系统连接的程序。以下是我需要序列化以创建帐户的对象:
[XmlRoot("record")]
class XmlUser
{
[XmlElement("login")]
public string Username { get; set; }
[XmlElement("password")]
[XmlElement("password_confirmation")]
public string Password { get; set; }
// Other attributes...
}
在一个属性上有两个XmlElementAttributes
会抛出异常,说我需要添加XmlChoiceIdentifierAttribute
。我不需要反序列化对象。我应该放弃这种方法,只使用XmlWriter
?
答案 0 :(得分:2)
你可以,
[XmlElement("password")]
public string Password { get; set; }
[XmlElement("password_confirmation")]
public string PasswordConfirmation{ get { return Password;} set; }