XSD vs Dingo
For those totally new to C# and have no clue what XmlSerializer is. I hope this provides a basic introduction to how attributes work with XmlSerializer and why Dingo generates all that square bracket stuff. If you happen to have fallen asleep the last two decades, a popular trend is including application metadata with objects. In .NET, they are attribute objects. In Java, it's called annotation.
I can hear some people saying, "So what's the big freaking deal with metadata? It's not new and has been around for a while." Metadata has been around for quite a while and those who pay attention to history can trace the roots of attributes/annotations. Unlike normal object metadata like field type and object type definition, metadata tries to address the needs of application frameworks. Sorry for the buzzwords. Say you have a cool GUI framework for getting data and updating the data dynamically. In a general sense, that can be considered a framework. Let's say the framework uses event listeners and messaging. Usually, not all data is dynamic and some are "less" dynamic than others. By "less dynamic", I mean data that can be reloaded by user actions. Typically, it's data that doesn't change often and does have to be absolutely up to date.
In a complex GUI application, there's going to be many objects. There are numerous approaches to organizing the metadata so the framework can determine which objects need to register for events. Before Microsoft, IBM and Sun started to push attributes/annotations, developers would write their own metadata framework for mapping object metadata and loading it at runtime. Metadata makes this type of work less tedious and more enjoyable. In the case of classes generated by Dingo, the metadata is required by XmlSerializer. What the metadata does is give the serializer hints about which objects to instantiate and which fields or properties to ignore.
In theory and practice, having metadata support at the language level should be more efficient at runtime. Of course, it can be abused like anything else, so it's not a magic bullet. If we look at how AspectWerkz tackled the problem, it's obvious annotations/attributes aren't critical. It makes life easier, but by no means is it a hammer for every problem. In a recent interview with bill joy, he expressed mixed feelings about annotations. To learn more about how how AspectWerkz deals with application metadata, go to their website.
There's an easy way to see how metadata affects XmlSerializer, remove the metadata from "Person" property. What happens is XmlSerializer will duplicate the data when an object is serialized out to XML.
As you can see from the XML output, without "XmlIgnoreAttribute", the serializer simply duplicates the same data. If we contrast this to XStream, annotations aren't necessary. I haven't read through all of XStream source yet, so I don't know exactly how Joe uses runtime reflection to determine which classes to instantiate. I hope this introduction provides a decent explanation of how XmlSerializer works and why Dingo generates it.
Updated 9-10-2004 Peter
|Copyright 2004 Peter Lin|