19

I have some Xml that I need to deserialize into an object. The Xml is:

<Person>
  <Type id="1234">Bob</Type>
</Person>

and the classes are:

public class Person { public Type Type; }
public class Type {
   [XmlAttribute("id")]
   public string id;
   // another property for value "Bob" here, such as:
   public string value;  // ????
}

I'd like to deserialize this Xml using XmlSerializer.Deserialize, into the concrete objects above (avoiding using XPath, etc.)

What Xml attribute can I decorate the "Type" class with so that I have not only an "id" attribute but also a value ("Bob")?

dotNetkow
  • 5,053
  • 4
  • 35
  • 50

1 Answers1

28

You would have to add a property like

[XmlText]
public string Text;
Lourens
  • 1,510
  • 1
  • 13
  • 27