简体   繁体   English

如何将简单的xml节点值反序列化为复合类型?

[英]How do you deserialize a simple xml node value into a composite type?

I have xml that looks something like this: 我有看起来像这样的xml:

<Policy>
  <Number>10-13-123123</number>
</Policy>

And a types like this: 像这样的类型:

class Policy
{
    [DataMember]
    PolicyNumber Number {get;set;}
}
class PolicyNumber
{
    [DataMember]
    public int Num1 {get;set;}
    [DataMember]
    public int Num2 {get;set;}
    [DataMember]
    public int Num3 {get;set;}
}

I need to run a method to split the Xml value up into the 3 properties 我需要运行一种将Xml值分成3个属性的方法

How can I get code to run during the XmlSerializer deserialize process to process the Xml value into a new instance of the composite type? 如何在XmlSerializer反序列化过程中运行代码,以将Xml值处理为复合类型的新实例?

You must implement IXmlSerializable in one (or both) of these classes to support what you want. 您必须在其中一个(或两个)类中实现IXmlSerializable ,以支持所需的内容。

http://msdn.microsoft.com/en-us/library/system.xml.serialization.ixmlserializable.aspx http://msdn.microsoft.com/en-us/library/system.xml.serialization.ixmlserializable.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM