开发者

how to control the xml output during serialization

开发者 https://www.devze.com 2023-03-04 18:06 出处:网络
if any property is blank or null then for that property xml tag is generated like </Attention> but i want to generate it like <Attention></Attention>. so impleme开发者_如何学运维nt I

if any property is blank or null then for that property xml tag is generated like </Attention> but i want to generate it like <Attention></Attention>. so impleme开发者_如何学运维nt IXmlSerializable interface and from the WriteXml() method i tried to change the xml tag when the value is null or empty but still not getting right output. so please tell me what i need to do to generate the xml tag like <Attention></Attention> this if my Attention property is null or empty. basically i want customization of xml output. please guide me.


I had to implement this once because the server that was receiving my Xml would crash on such tags. I wouldn't go implement your own serialization code, but instead do some post-processing (Regex.Replace()) after serialization, keeping the rest of your code clean.

0

精彩评论

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

关注公众号