When I look at your intended names, I feel that your naming is somewhat
artificial. For example, why would you prefer the element
csCollDocuments
to just
Documents
. First idea which comes to mind is: you are trying to introduce a notion unique to the application, possibly to avoid naming conflict with some other
Documents
, as all the words are widely used. That looks like a call for much more comprehensive expression tool, such as XML namespaces. Please see:
http://en.wikipedia.org/wiki/XML_namespace[
^],
http://www.w3.org/TR/2006/REC-xml-names11-20060816/[
^].
Everything in your code, the style you define your data model (which I like), the structure — tells me that you probably need different, much more consistent approach called
Data Contract.
Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx[
^].
This approach is most flexible and at the same time easiest for development and most non-intrusive.
Please see my past answers where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[
^],
Creating property files...[
^],
deseralize a json string array[
^].
There are many important features in this approach, but in particular, you can use different attribute to modify naming, both name itself via the
Name
of the
[DataMember]
attribute and
Namespace
of the
[DataContract]
attribute. Please see:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx[
^].
[EDIT]
In response to the follow-up discussion and just in case:
Even though the Data Contract could totally solve your problem, you might face the situation where the persistent data format might need some deep customization, due the some peculiarities of the external system. In such difficult cases, the solution is always possible using most flexible XML parsing and generation classes
System.Xml.XmlTextWriter
and
System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
Please see:
http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[
^].
—SA