1) If you need flexibility then you should definitely go with the
XmlSerializer
2) What constitutes a new version? What are the parameters of your project?
Is a new version a doc format with additional children? New top level
elements? Do they need to be backwards compatible? Should they NOT be
backwards compatible?
3) that depends if you ever need to be able to validate new documents
against old schemas. If you do, then the schemas need to indicate where to
expect extensions through the any and anyAttribute constructs.
4) The XmlSerializer will not deserialize any content that it does not
recognize and it only recognizes content that matches the types that were
passed in to the constructor of the particular XmlSerializer instance.
Unless you are planning to do some fancy stuff with reflection you will
always need the deserialization libraries present when your program is
executing. The serializer will throw an exception when it does not recognize
the root element in the document you are serializing.You can catch that
exception and report it in the way your application expects it. You can also
register delegates (callbacks) to receive notifications about unrecognized
XML content. You can use this mechanism to report your own errors as well.
Did this help?
--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor
"William Gant" <wg***@transcender.com> wrote in message
news:36**************************@posting.google.c om...
1) I actually haven't written the serialization code yet. I probably
need to use the more flexible method. I'm assuming that ISerializable
and a formatter would be best. How do I handle versioning in this
case?
2) I haven't really decided how to handle a new version. What options
do I have?
3) Is there anything special I need to do to the schema to allow for
versioning?
4) It may be that I just have to give an error message when the user
doesn't have the object libraries required to load a specific object
on deserialization. I think it would be nice to be able to load the
base class for the object, but after considering it, doing so will
offer no real benefit since the object can not be correctly serialized
again later on.
"Christoph Schittko [MVP]" <ch********************@austin.rr.com> wrote in
message news:<#a*************@TK2MSFTNGP11.phx.gbl>...
1) Are you serializing via the XmlSerializer, then ISerializable is not
in the picture. If you serialize via the SoapFormatter/BinaryFormatter and
you expect that you need to handle versioning it is best to implement
ISerializable.
XmlSerialization is a lot more forgiving than runtime serialization, but
doesn't provide as many hooks to customize processing either.
2) What are you trying to achieve? How can one identify a new version?
Is a new version identified by a new XML namespace?
3) Take a look at some of the XML tools out there. The schema editor in
VS.NET is bareable for smaller schemas, but you may want more
user-friendlyness of you are working with larger schemas.
4) I am not sure, what you mean. The XmlSerializer does not support lazy
loading of documents, but it can handle optional elements, i.e. it
doesn't require a full document to deserialize it.
--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor
"William Gant" <wg***@transcender.com> wrote in message
news:36**************************@posting.google.c om... Ok,
I have a project that is destined for continual growth and development
over the next few years (benign scope creep). The object model is
relatively generic at the moment, but will be extended considerably
over time, mostly using inheritance.
Each document will have a single element at the root and it will
contain a collection of objects that are based off of a finite number
of base classes. However, these objects may have numerous child
classes and I can not guarantee that the child classes won't be
containers themselves. References will be allowed between objects of
different base types, but not between objects of the same base type.
Here are my questions:
1) How should I serialize these objects to make sure that my
serialization mechanism continues to work well over time? Should I
implement ISerializable?
2) How hard is it to implement document versioning?
3) How would you suggest creating and maintaining a schema so that I
can validate the contents of the documents.
4) Some of the child classes being serialized may not be present when
I attempt to deserialize - I'd like to just load the base class when
this happens. Is this possible?
Thanks in advance for your help,
William Gant
wg***@transcenderNOSPAM.com