Reputation: 249
I am using XmlSerializer to generate XML output for my class. Is it possible to create a custom XMLSerializer that have all the xml nodes in lower case? I do not want to add attributes to every field field from my class to specify the node in lower case.
Thank you, Angela
Upvotes: 6
Views: 4739
Reputation: 15794
The best example I've seen over the years is found here, written by Daniel Cazzulino. I find it extremely elegant because he overrides the XmlTextReader
and XmlWriter
to make the serialization do exactly what he wants it to do. Hope you enjoy reading his blog!
Upvotes: 2
Reputation: 1063338
It depends how much work you want to do. Adding attributes is the easiest option, but you say you don't want to do that. You could name the classes with lower-case names, but that is a horrible way of approaching this, IMO.
You can tell XmlSerializer
what to do at runtime, by using XmlAttributeOverrides
- but then you need to use reflection to tell it about all the members you want to tweak, but note: if you do this, you must cache and re-use such a serializer; if you create a new XmlSerializer
via XmlAttributeOverrides
every time, you will leak assemblies memory.
There's an example on MSDN
Upvotes: 4