473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

XML Serialization and custom collections

I am getting XML from a dataset that has been populated via a storedprocedure
no schemas have been applied nor any relationships. But the correct table
names have been given to match the table(s) equivalent business object(s). I
have a custom collection that implements ICollection and IEnumerable.

Here is the collection:

Imports ERP.BusinessObjects
Imports ERP.BusinessObjects.Helpdesk
Imports ICTObjects.Collections

Imports System.Xml.Serialization
Namespace Collections

<Serializable()> _
Public Class BusinessObjectCollection : Implements ICollection,
IEnumerable

Private _businessObjectCollection As ArrayList = New ArrayList
Public Sub New()
MyBase.New()
End Sub

Default Public Overloads ReadOnly _
Property Item(ByVal index As Integer) As ERPBusinessObject
Get
Return CType(_businessObjectCollection(index),
ERPBusinessObject)
End Get
End Property

Public Sub CopyTo(ByVal a As Array, ByVal index As Integer) _
Implements ICollection.CopyTo
_businessObjectCollection.CopyTo(a, index)
End Sub

Public ReadOnly Property Count() As Integer Implements _
ICollection.Count
Get
Count = _businessObjectCollection.Count
End Get

End Property

Public ReadOnly Property SyncRoot() As Object _
Implements ICollection.SyncRoot
Get
Return Me
End Get
End Property

Public ReadOnly Property IsSynchronized() As Boolean _
Implements ICollection.IsSynchronized
Get
Return False
End Get
End Property
Public Function GetEnumerator() As IEnumerator _
Implements IEnumerable.GetEnumerator

Return _businessObjectCollection.GetEnumerator()
End Function

Public Function Add(ByVal businessObject As ERPBusinessObject) As
Integer
_businessObjectCollection.Add(businessObject)
Return _businessObjectCollection.Count
End Function
End Class

This collection stores ERPBusinessObject(s) which the business object "Case"
inherits I have the following XML from the dataset:

<BusinessObjectCollection>
<Cases>
<CaseStatus_Status>Request Recieved</CaseStatus_Status>
<ID>1001105</ID>
<SLAAgreement_CallTypeID>Requests</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>CRupa</Owner>
<NatureOfCase>Testing 1</NatureOfCase>
<TimeReported>2005-05-24T12:26:41.8200000+01:00</TimeReported>
<Comments />
<DateCreated>2005-05-24T12:26:41.8200000+01:00</DateCreated>
<Modified>2005-05-24T12:27:00.0000000+01:00</Modified>
<ChangeUser>womber</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>Request Recieved</CaseStatus_Status>
<ID>1001106</ID>
<SLAAgreement_CallTypeID>Requests</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Testing 2</NatureOfCase>
<TimeReported>2005-05-24T12:28:40.0430000+01:00</TimeReported>
<Comments>Comment entruy</Comments>
<DateCreated>2005-05-24T12:28:40.0430000+01:00</DateCreated>
<Modified>2005-05-24T15:09:00.0000000+01:00</Modified>
<ChangeUser>womber</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>Request Accepted</CaseStatus_Status>
<ID>1001107</ID>
<SLAAgreement_CallTypeID>Requests</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Testing 3</NatureOfCase>
<TimeReported>2005-05-24T12:32:20.0830000+01:00</TimeReported>
<Comments />
<DateCreated>2005-05-24T12:32:20.0830000+01:00</DateCreated>
<Modified>2005-06-19T01:26:00.0000000+01:00</Modified>
<ChangeUser>ME</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>Request Accepted</CaseStatus_Status>
<ID>1001108</ID>
<SLAAgreement_CallTypeID>Requests</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Testing 4</NatureOfCase>
<TimeReported>2005-05-24T12:40:10.1670000+01:00</TimeReported>
<Comments>Test</Comments>
<DateCreated>2005-05-24T12:40:10.1670000+01:00</DateCreated>
<Modified>2005-05-24T12:45:00.0000000+01:00</Modified>
<ChangeUser>womber</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>On Hold</CaseStatus_Status>
<ID>1001109</ID>
<SLAAgreement_CallTypeID>Network</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Testing 5</NatureOfCase>
<TimeReported>2005-05-24T12:47:33.1270000+01:00</TimeReported>
<Comments>Test</Comments>
<DateCreated>2005-05-24T12:47:33.1270000+01:00</DateCreated>
<Modified>2005-06-21T02:24:00.0000000+01:00</Modified>
<ChangeUser>ME</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>On Hold</CaseStatus_Status>
<ID>1001110</ID>
<SLAAgreement_CallTypeID>Network</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Test 6</NatureOfCase>
<TimeReported>2005-05-24T12:55:02.0700000+01:00</TimeReported>
<Comments />
<DateCreated>2005-05-24T12:55:02.0700000+01:00</DateCreated>
<Modified>2005-06-21T02:27:00.0000000+01:00</Modified>
<ChangeUser>ME</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>In Progress</CaseStatus_Status>
<ID>1001111</ID>
<SLAAgreement_CallTypeID>Network</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Testing 8</NatureOfCase>
<TimeReported>2005-05-24T13:00:15.8970000+01:00</TimeReported>
<Comments>Test</Comments>
<DateCreated>2005-05-24T13:00:15.8970000+01:00</DateCreated>
<Modified>2005-06-21T02:31:00.0000000+01:00</Modified>
<ChangeUser>ME</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>Closed</CaseStatus_Status>
<ID>1001112</ID>
<SLAAgreement_CallTypeID>Intranet Update</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>testing</NatureOfCase>
<TimeReported>2005-05-24T13:06:20.3030000+01:00</TimeReported>
<Comments />
<DateCreated>2005-05-24T13:06:20.3030000+01:00</DateCreated>
<Modified>2005-05-24T13:06:00.0000000+01:00</Modified>
<ChangeUser>womber</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>Request Recieved</CaseStatus_Status>
<ID>1001113</ID>
<SLAAgreement_CallTypeID>Requests</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Test full text</NatureOfCase>
<TimeReported>2005-05-24T13:12:02.7700000+01:00</TimeReported>
<Comments>Test</Comments>
<DateCreated>2005-05-24T13:12:02.7700000+01:00</DateCreated>
<Modified>2005-05-24T13:12:00.0000000+01:00</Modified>
<ChangeUser>womber</ChangeUser>
</Cases>
</BusinessObjectCollection>

I have tried overriding xmlattributes and nothing seems to work. I either
get an error saying the XMLType and XRoot cannot be overridden or the Cases
objects do not get deserialised. If the collection was strongly typed to
Cases it will work but I want this collection to be able to deserialise all
objects that are inherited from ERPBusinessObject. And I also know about
XMLInclude but that only works on objects serialised by .NET. Any ideas or is
this a non-starter. If this does not work I would have to create a custom
collection for every class derived from ERPBusinessObject. Which is horrible.
Nov 12 '05 #1
1 1620
In this case since you are building a heterogeneous collection of typed
objects, you will probably have to implement IXmlSerializable and do the
element to type mapping yourself in the ReadXml and WriteXml methods. Just
return null from GetSchema().

"womber" <wo****@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
I am getting XML from a dataset that has been populated via a
storedprocedure
no schemas have been applied nor any relationships. But the correct table
names have been given to match the table(s) equivalent business object(s).
I
have a custom collection that implements ICollection and IEnumerable.

Here is the collection:

Imports ERP.BusinessObjects
Imports ERP.BusinessObjects.Helpdesk
Imports ICTObjects.Collections

Imports System.Xml.Serialization
Namespace Collections

<Serializable()> _
Public Class BusinessObjectCollection : Implements ICollection,
IEnumerable

Private _businessObjectCollection As ArrayList = New ArrayList
Public Sub New()
MyBase.New()
End Sub

Default Public Overloads ReadOnly _
Property Item(ByVal index As Integer) As ERPBusinessObject
Get
Return CType(_businessObjectCollection(index),
ERPBusinessObject)
End Get
End Property

Public Sub CopyTo(ByVal a As Array, ByVal index As Integer) _
Implements ICollection.CopyTo
_businessObjectCollection.CopyTo(a, index)
End Sub

Public ReadOnly Property Count() As Integer Implements _
ICollection.Count
Get
Count = _businessObjectCollection.Count
End Get

End Property

Public ReadOnly Property SyncRoot() As Object _
Implements ICollection.SyncRoot
Get
Return Me
End Get
End Property

Public ReadOnly Property IsSynchronized() As Boolean _
Implements ICollection.IsSynchronized
Get
Return False
End Get
End Property
Public Function GetEnumerator() As IEnumerator _
Implements IEnumerable.GetEnumerator

Return _businessObjectCollection.GetEnumerator()
End Function

Public Function Add(ByVal businessObject As ERPBusinessObject) As
Integer
_businessObjectCollection.Add(businessObject)
Return _businessObjectCollection.Count
End Function
End Class

This collection stores ERPBusinessObject(s) which the business object
"Case"
inherits I have the following XML from the dataset:

<BusinessObjectCollection>
<Cases>
<CaseStatus_Status>Request Recieved</CaseStatus_Status>
<ID>1001105</ID>
<SLAAgreement_CallTypeID>Requests</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>CRupa</Owner>
<NatureOfCase>Testing 1</NatureOfCase>
<TimeReported>2005-05-24T12:26:41.8200000+01:00</TimeReported>
<Comments />
<DateCreated>2005-05-24T12:26:41.8200000+01:00</DateCreated>
<Modified>2005-05-24T12:27:00.0000000+01:00</Modified>
<ChangeUser>womber</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>Request Recieved</CaseStatus_Status>
<ID>1001106</ID>
<SLAAgreement_CallTypeID>Requests</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Testing 2</NatureOfCase>
<TimeReported>2005-05-24T12:28:40.0430000+01:00</TimeReported>
<Comments>Comment entruy</Comments>
<DateCreated>2005-05-24T12:28:40.0430000+01:00</DateCreated>
<Modified>2005-05-24T15:09:00.0000000+01:00</Modified>
<ChangeUser>womber</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>Request Accepted</CaseStatus_Status>
<ID>1001107</ID>
<SLAAgreement_CallTypeID>Requests</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Testing 3</NatureOfCase>
<TimeReported>2005-05-24T12:32:20.0830000+01:00</TimeReported>
<Comments />
<DateCreated>2005-05-24T12:32:20.0830000+01:00</DateCreated>
<Modified>2005-06-19T01:26:00.0000000+01:00</Modified>
<ChangeUser>ME</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>Request Accepted</CaseStatus_Status>
<ID>1001108</ID>
<SLAAgreement_CallTypeID>Requests</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Testing 4</NatureOfCase>
<TimeReported>2005-05-24T12:40:10.1670000+01:00</TimeReported>
<Comments>Test</Comments>
<DateCreated>2005-05-24T12:40:10.1670000+01:00</DateCreated>
<Modified>2005-05-24T12:45:00.0000000+01:00</Modified>
<ChangeUser>womber</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>On Hold</CaseStatus_Status>
<ID>1001109</ID>
<SLAAgreement_CallTypeID>Network</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Testing 5</NatureOfCase>
<TimeReported>2005-05-24T12:47:33.1270000+01:00</TimeReported>
<Comments>Test</Comments>
<DateCreated>2005-05-24T12:47:33.1270000+01:00</DateCreated>
<Modified>2005-06-21T02:24:00.0000000+01:00</Modified>
<ChangeUser>ME</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>On Hold</CaseStatus_Status>
<ID>1001110</ID>
<SLAAgreement_CallTypeID>Network</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Test 6</NatureOfCase>
<TimeReported>2005-05-24T12:55:02.0700000+01:00</TimeReported>
<Comments />
<DateCreated>2005-05-24T12:55:02.0700000+01:00</DateCreated>
<Modified>2005-06-21T02:27:00.0000000+01:00</Modified>
<ChangeUser>ME</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>In Progress</CaseStatus_Status>
<ID>1001111</ID>
<SLAAgreement_CallTypeID>Network</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Testing 8</NatureOfCase>
<TimeReported>2005-05-24T13:00:15.8970000+01:00</TimeReported>
<Comments>Test</Comments>
<DateCreated>2005-05-24T13:00:15.8970000+01:00</DateCreated>
<Modified>2005-06-21T02:31:00.0000000+01:00</Modified>
<ChangeUser>ME</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>Closed</CaseStatus_Status>
<ID>1001112</ID>
<SLAAgreement_CallTypeID>Intranet Update</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>testing</NatureOfCase>
<TimeReported>2005-05-24T13:06:20.3030000+01:00</TimeReported>
<Comments />
<DateCreated>2005-05-24T13:06:20.3030000+01:00</DateCreated>
<Modified>2005-05-24T13:06:00.0000000+01:00</Modified>
<ChangeUser>womber</ChangeUser>
</Cases>
<Cases>
<CaseStatus_Status>Request Recieved</CaseStatus_Status>
<ID>1001113</ID>
<SLAAgreement_CallTypeID>Requests</SLAAgreement_CallTypeID>
<SLAAgreement_Priority>Medium</SLAAgreement_Priority>
<GroupPermissions_GroupID>0</GroupPermissions_GroupID>
<ERPOperator_Name>womber</ERPOperator_Name>
<Owner>womber</Owner>
<NatureOfCase>Test full text</NatureOfCase>
<TimeReported>2005-05-24T13:12:02.7700000+01:00</TimeReported>
<Comments>Test</Comments>
<DateCreated>2005-05-24T13:12:02.7700000+01:00</DateCreated>
<Modified>2005-05-24T13:12:00.0000000+01:00</Modified>
<ChangeUser>womber</ChangeUser>
</Cases>
</BusinessObjectCollection>

I have tried overriding xmlattributes and nothing seems to work. I either
get an error saying the XMLType and XRoot cannot be overridden or the
Cases
objects do not get deserialised. If the collection was strongly typed to
Cases it will work but I want this collection to be able to deserialise
all
objects that are inherited from ERPBusinessObject. And I also know about
XMLInclude but that only works on objects serialised by .NET. Any ideas or
is
this a non-starter. If this does not work I would have to create a custom
collection for every class derived from ERPBusinessObject. Which is
horrible.

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
0
by: CJ Taylor | last post by:
hey everyone, thought I would ask this here because the web service groups seems pretty light on conversation. I'm buliding a web service, but keep getting this error. I understand the error,...
10
by: SStory | last post by:
My app is near completed for the basic feature of version 1.0. I have an extensive object model and I now want to persist my objects using serialization. I have chosen binaryformatter to...
1
by: Dennis C. Drumm | last post by:
New for .net framework 2.0 is version tolerant serialization. To use this new feature, do I also need to use the new generics types for collections, e.g. SortedList? Thanks, Dennis
2
by: Justin Crites | last post by:
I have an object which I want to be serializable. I have marked with with . The object only has a single data member, which is a LinkedList<int>. This linked list is a private member and cannot...
5
by: Harold Howe | last post by:
I am having a problem deserializing objects from a library when the following conditions exist: 1- The library is strongly named 2- The serialized file was created with version 1.0 of the...
0
by: crazyone | last post by:
I've got a gaming framework i'm building and i want to save myself the trouble of reading and writting the complete game data to a custom file and load/save it to an XML file but i'm getting...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.