All,
I have quite a challenging task ahead of me. I need to write an object model
(for code access) based on a schema, which cannot be made into a dataset
because of it's complexity.
So I created a couple of objects and serializing it into XML based upon the
schema works perfectly.
The XML / Schema looks something like this:
<? xml ?>
<Root>
<KnownElement1></KnownElement1>
<KnownElement2></KnownElement2>
...
<WeirdElementContainer>
<WeirdElement>
</WeirdElement>
</WeirdElementContainer>
</Root>
The only problem lies with the 'WeirdElement'. This tag contains different
information per schema. Since I am a very lazy programmer I just want to
write the object model once, and not per schema.
I thought of a solution to my problem. First I could create a base
'WeirdElement' class and inherit my other objects. So I would get something
like this:
[System.Xml.Serialization.XmlInclude(typeof(NotSoWe irdElement))]
public class WeirdElement
{
}
But, when serializing this I would get a "xsi:type=" attribute in the
WeirdElement XML tag and that is not desirable because of the schema.
What I would really like to do is create a custom serializer per
WeirdElement class. In pseudo code it goes something like this:
XmlSerializer xs = new XmlSerializer(typeof(Root));
[System.Xml.Serialization.UseXmlSerializer(typeof(M yWeirdElementSerializer))]
public class WeirdElement
{
}
xs.Serialize(myRootObject);
I would basically like to run my own custom serializer whenever the 'normal'
serializer encounters my WeirdElement property. That way I could create or
parse the XML according to the rules set by the current schema.
If anyone knows how to do this or how to solve this problem any other way,
please let me know...
Thanks in advance,
Ivo Bronsveld
Lead Developer e-Clubs
www.e-clubs.nl
<< When replying directly to me, please remove the nospam from my e-mail>>