I have some XML that I am trying to deserialize the xml below.
<?xml version="1.0" encoding="UTF-8"?>
<disproot version="1.0">
<header>
<msg-type> init_req </msg-type>
<txn-id> 0090 </txn-id>
</header>
<body />
</disproot>
My object is something like this.
[XmlRoot("disproot")]
public class Request
{
[XmlAttribute("version")]
public string Version
{ get; set; }
[XmlElement("header", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
Header header = new Header();
}
public class Header
{
public Header()
{
}
[XmlElement("txn-id")]
public string TransactionId
{
get;
set;
}
[XmlElement("msg-type")]
public string MessageType
{
get;
set;
}
}
My Header’s object is not populated. The members are displaying as Null values. See below.
Request.Header.TasnsactionId’s value is Null
Request.Header.MessageType’s value is also Null
Anything wrong I am doing here?
Any help would be appreciable.
XML serialization works only on public members. So, you can change the field to
and it should work fine. Although I would advise you against using public fields, you should probably make it into a property: