XSD.EXE array, would like list
-
I used XSD.EXE to convert my schema to a C# class. The tool creates arrays to represent elements whose maxOccurs attribute is unbounded. Arrays are very limiting: you cannot add or delete items without a lot of shuffling. Has anyone found a way around this limitation of arrays? For simple cases, I have converted the array to a List and back to an array, but that is only useful in the simplest of cases. Perhaps there is another tool that can convert my schema and use a list or some other suitable container (?).
-
I used XSD.EXE to convert my schema to a C# class. The tool creates arrays to represent elements whose maxOccurs attribute is unbounded. Arrays are very limiting: you cannot add or delete items without a lot of shuffling. Has anyone found a way around this limitation of arrays? For simple cases, I have converted the array to a List and back to an array, but that is only useful in the simplest of cases. Perhaps there is another tool that can convert my schema and use a list or some other suitable container (?).
There is no need for converting the list back to an array, you can replace it. I did that e.g. with GPX files (see also Bernie’s Trackviewer[^] where I use some more tricks for getting "nice" classes from an "ugly" XML schema).
-
There is no need for converting the list back to an array, you can replace it. I did that e.g. with GPX files (see also Bernie’s Trackviewer[^] where I use some more tricks for getting "nice" classes from an "ugly" XML schema).
I am not sure what you mean by "replace it." Do you mean change the implementation of the class produced by XSD.EXE? My process is: - convert class array to List (ToList()) - make my changes (add, delete, modify) - assign back to class array (myList.ToArray)
-
There is no need for converting the list back to an array, you can replace it. I did that e.g. with GPX files (see also Bernie’s Trackviewer[^] where I use some more tricks for getting "nice" classes from an "ugly" XML schema).
-
I used XSD.EXE to convert my schema to a C# class. The tool creates arrays to represent elements whose maxOccurs attribute is unbounded. Arrays are very limiting: you cannot add or delete items without a lot of shuffling. Has anyone found a way around this limitation of arrays? For simple cases, I have converted the array to a List and back to an array, but that is only useful in the simplest of cases. Perhaps there is another tool that can convert my schema and use a list or some other suitable container (?).
-
Same basic question as the OP. Looking at your source code it appears that you made manual changes to the generated files? And then fixed the actual serialization problem with XmlElementAttribute?
Exactly.
-
I used XSD.EXE to convert my schema to a C# class. The tool creates arrays to represent elements whose maxOccurs attribute is unbounded. Arrays are very limiting: you cannot add or delete items without a lot of shuffling. Has anyone found a way around this limitation of arrays? For simple cases, I have converted the array to a List and back to an array, but that is only useful in the simplest of cases. Perhaps there is another tool that can convert my schema and use a list or some other suitable container (?).
That is precisely what Collections are for -- to address the limitations imposed by fixed length arrays. The limitation is not on arrays -- it appears to be on how willing programmers are to writing proper code, IMHO. In C++, the standard library has some things for that, like vectors and maps, and in C# there are collections.
-
That is precisely what Collections are for -- to address the limitations imposed by fixed length arrays. The limitation is not on arrays -- it appears to be on how willing programmers are to writing proper code, IMHO. In C++, the standard library has some things for that, like vectors and maps, and in C# there are collections.
I think you do not understand the question. The problem is that the tool (XSD.EXE) generates code that uses arrays. Arrays are limiting since it is difficult to add to or remove items from them. I was looking for another tool (that used a more appropriate collection) or an easy workaround. Perhaps I could have phrased my question better. The limitation I mentioned was intended to mean that the tool generated arrays, not that of arrays themselves. Even at this late stage, I appreciate your answer. However, I believe you misread the question.