1

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 implement 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.

1
  • 2
    There's a difference between blank and null (for strings, in particular); and null values are generally omitted rather than included as empty. However the self-closed <Attention/> is perfectly fine xml for an empty element. If you have a separate parser that complains about that, then the parser is at fault, not the serializer. Commented May 9, 2011 at 7:06

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.