Groups | Blog | Home
all groups > dotnet xml > october 2005 >

dotnet xml : deserialize IEnumerable with anyType tags


Achim Domma (SyynX Solutions GmbH)
10/26/2005 9:34:25 PM
Hi,

I have a data structure which is serialzied into an xml like this:

<?xml version="1.0" encoding="utf-8"?>
<Storage xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Frames>
<Frame Index="0">
<Tags>
<anyType xsi:type="ProjectInfo">
<ProjectType>MediaTags.Projects.FACS</ProjectType>
<MediaFile>C:\develop\JustForFun\Dyade07divx.avi</MediaFile>
</anyType>
</Tags>
</Frame>
<Frame Index="98">
<Tags>
<anyType xsi:type="FacsTag">
<id>7</id>
</anyType>
</Tags>
</Frame>
</Frames>
</Storage>

If I try to deserialize this structure, everything works fine up to the
level of Tags. Tags is a class, which implements IEnumerable and the
required Add(object o) method.

But Add is not called with instances of ProjectInfo and FacsTag. It's
called with arrays of objects. The first entry is the xsi:type Attribute
followed by the child nodes of the anyType tag.

Is that correct behavior? I would have expected that the ProjectInfo and
FacsTag objects are deserialzied too. Is there something I have to do to
enable this functionality?

regards,
Achim Domma (SyynX Solutions GmbH)
10/29/2005 12:00:00 AM
[quoted text, click to view]

Just for the records, answering my own question:

The relevant data types were not known to the deserializer. I wondered
on how to tell the deserialzier about them, because you can pass types
to the Serialize function, but not to Deserialze. The solution is to
pass the types to the ctor of the serialzizer.

The following article was very helpfull in figuring out how
serializing/deserializing works:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp

regards,
AddThis Social Bookmark Button