开发者

C# deserialization

I have a question about deserialization. It's a part of xml file

<N Name="MyName">Number of MyName</N>

and class in c开发者_如何学JAVA#:

MyN
{
  [XmlAttribute(AttrName='Name')]
  public string Name {get;set;}

  public string Number {get;set}
}

I want to make that value of N in xml file (in samle - "Number of MyName") will deserialze in property Number of MyN class.

Thanks.


Use [XmlText()] Attribute

[XmlRoot(ElementName="N")]
MyN
{
    [XmlAttribute(AttrName='Name')]
    public string Name {get;set;}
    [XmlText()]
    public string Number {get;set}
}

Check this for more information about Xml Serialization in C# http://www.dotnetjohn.com/articles.aspx?articleid=173


[XmlRoot(ElementName="N")]
public class MyN
{
    [XmlAttribute]
    public string Name { get; set; }
    public string Number { get; set; }
}


MyN
{
  [XmlAttribute(AttrName='Name')]
  public string Name {get;set;}

  [XmlText]
  public string Number {get;set}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜