dekko
dekko

Reputation: 148

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#:

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.

Upvotes: 0

Views: 409

Answers (3)

viky
viky

Reputation: 17689

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

Upvotes: 5

Adrian Zanescu
Adrian Zanescu

Reputation: 8008

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

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

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039438

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

Upvotes: 3

Related Questions