I have a class which has property whiches type is char as following
[XmlRoot("Root")]
public class TestClass
{
[XmlElement("Test", typeof(char))]
public char TestProperty { get; set; }
}
When value of TestProperty is 'N' and if I serialize TestClass it will produce following result:
<Root>
<Test>78</Test>
</Root>
But what I want is to have following
<Root>
<Test>N</Test>
</Root>
Is it possible without changing type of TestProperty to string?
The XmlSerializer enables you to control how objects are encoded into XML, it has a number of constructors. If you use any of the constructors other than the one that takes a type then a new temporary assembly is created EVERY TIME you create a serializer, rather than only once.
Xml Serializer serializes only public member of object but Binary Serializer serializes all member whether public or private. In Xml Serialization, some of object state is only saved but in Binary Serialization, entire object state is saved.
By applying the XmlRootAttribute, you can control the XML stream generated by the XmlSerializer. For example, you can change the element name and namespace. The XmlTypeAttribute allows you to control the schema of the generated XML.
XML serialization is the process of converting XML data from its representation in the XQuery and XPath data model, which is the hierarchical format it has in a Db2® database, to the serialized string format that it has in an application.
Not AFAIK. You can cheat, though:
[XmlIgnore]
public char TestProperty { get; set; }
[XmlElement("Test"), Browsable(false)]
public string TestPropertyString {
get { return TestProperty.ToString(); }
set { TestProperty = value.Single(); }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With