473,386 Members | 1,815 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,386 software developers and data experts.

Serializing a collection

Hi

I am trying to serialize a collection of GUIDs by overriding the
serialize function on a diagram component I am using.
The following code sucessfully serializes a single GUID:

Public Overloads Overrides Function Serialize(ByVal Key As Object) As
String
Dim objXML As New XmlDocument
Dim objParent As XmlElement
objParent = objXML.CreateElement("InteractionShape")
objParent.SetAttribute("InteractionGUID", _
m_InteractionGUID.ToString) <-----change to
collection
objParent.InnerXml = MyBase.Serialize(Key)
Return objParent.OuterXml
End Function

Which gives the following XML: (some XML deleted)

<InteractionShape InteractionGUID="50179760-9d24-4239-8029-0fb08be7630b">
</InteractionShape>


Does anyone know how to serialize a collection (where
m_InteractionGUID is a strongly typed collection of GUIDs rather than
a single GUID) to give something like the following XML?

<InteractionShape>
<InteractionGUID GUID="50179760-9d24-4239-8029-0fb08be7630b">
<InteractionGUID GUID="84611660-9d45-3575-3545-0bb08be5816f">
</InteractionShape>

- OR -

<InteractionShape>
<InteractionGUID>50179760-9d24-4239-8029-0fb08be7630b</InteractionGUID>
<InteractionGUID>84611660-9d45-3575-3545-0bb08be5816f</InteractionGUID>
</InteractionShape>

Kind regards, Carl
Nov 12 '05 #1
1 2862
You are building a DOM object and generating XML from it.

There is a different approach which is to deal with domain-specific objects,
and use the XML-serialization capabilities built into the .NET Framework to
generate the XML for you. In this way the XML is less intrusive into your
app. You still get the capability to read and write XML, but it is done
more implicitly.

For an example of serializing a strongly-typed collection of Guids, see
http://www.winisp.net/cheeso/srcview...ile=collect.vb
-D
"Carl Gilbert" <mr*************@hotmail.com> wrote in message
news:66**************************@posting.google.c om...
Hi

I am trying to serialize a collection of GUIDs by overriding the
serialize function on a diagram component I am using.
The following code sucessfully serializes a single GUID:

Public Overloads Overrides Function Serialize(ByVal Key As Object) As
String
Dim objXML As New XmlDocument
Dim objParent As XmlElement
objParent = objXML.CreateElement("InteractionShape")
objParent.SetAttribute("InteractionGUID", _
m_InteractionGUID.ToString) <-----change to
collection
objParent.InnerXml = MyBase.Serialize(Key)
Return objParent.OuterXml
End Function

Which gives the following XML: (some XML deleted)

<InteractionShape InteractionGUID="50179760-9d24-4239-8029-0fb08be7630b">
</InteractionShape>


Does anyone know how to serialize a collection (where
m_InteractionGUID is a strongly typed collection of GUIDs rather than
a single GUID) to give something like the following XML?

<InteractionShape>
<InteractionGUID GUID="50179760-9d24-4239-8029-0fb08be7630b">
<InteractionGUID GUID="84611660-9d45-3575-3545-0bb08be5816f">
</InteractionShape>

- OR -

<InteractionShape>
<InteractionGUID>50179760-9d24-4239-8029-0fb08be7630b</InteractionGUID> <InteractionGUID>84611660-9d45-3575-3545-0bb08be5816f</InteractionGUID> </InteractionShape>

Kind regards, Carl

Nov 12 '05 #2

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

Similar topics

1
by: dotNetDave | last post by:
I'm trying to create xml seriaizable collection class (below), but the xml keeps coming out wrong. In the resulting xml from the web service (below) the "ArrayOfAlarmProcessor" tag should really be...
3
by: Amy L. | last post by:
I am using the xml serializer to serialize the objects out of a collection into a file. The object that is being serialized is a class in my application. When I serialize my class it produces the...
2
by: Aleksei Guzev | last post by:
Imagine one writing a class library CL1 for data storage. He defines classes ‘DataItem’ and ‘DataRecord’ so that the latter contains a collection of the former. And he derives class ‘IntItem’ from...
0
by: JackRazz | last post by:
I'm trying to serialize a collection to a file stream by serializing each object individually. The code below works fine with the BinaryFormatter, but the SoapFormatter reads the first object and...
0
by: Michael Maercker | last post by:
Hi! I'm about to go nuts over my serializing problem. This is my situation: I have a Data-Class that can have children of the same class which are stored in a hashtable, i.e: X has A as a...
3
by: axr | last post by:
Having trouble with Serilization of objects that contain members which are of type Interface eg public class SomeClass { ISomeInterface1 itf1; ClassType1 ct1; ISomeInterface2 itf2;
3
by: RandomEngineer | last post by:
So here's the challenge... How can a collection (System.Collections.Generic.IList) of some custom type be serialized in a web service using .NET 2.0? Below are the class and the web methods in...
0
by: Yofnik | last post by:
Is there a way to avoid serializing an empty ArrayList? I would like the following class: public class Collection { public ArrayList Items = new ArrayList(); } ....to serialize like this:
1
by: Karthik1979 | last post by:
I have a custom class inherited from List<T> collection. Along with the base class functionality, I have included my additional properties. When serializing, only the base class items are serialized...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.