all groups > dotnet xml > july 2004 >
You're in the

dotnet xml

group:

Serializing a collection


Serializing a collection mr_carl_gilbert NO[at]SPAM hotmail.com
7/27/2004 3:27:20 AM
dotnet xml:
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>

Re: Serializing a collection Dino Chiesa [Microsoft]
7/27/2004 6:29:15 PM
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.aspx?dir=xml-serialization&file=collect.vb


-D


[quoted text, click to view]

AddThis Social Bookmark Button