Serializing 'unknown' objects



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(NotSoWeirdElement))]
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(MyWeirdElementSerializer))]
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>>


.



Relevant Pages

  • Re: Serializing unknown objects
    ... - A custom attribute which contains a mapping to Schema name and version. ... to the xml at the correct location. ... > 'WeirdElement' class and inherit my other objects. ... > What I would really like to do is create a custom serializer per ...
    (microsoft.public.dotnet.xml)
  • Handling multiple schemas and large files in XML
    ... and process some data that is made available to me as XML. ... different schema versions. ... Because of this, the application's internal object ... I could construct the object model by using an ...
    (microsoft.public.dotnet.xml)
  • Re: how to return xml document from a web service
    ... what specific XML you expect. ... If you have a schema that defines what you expect, ... The second issue with this approach is that XML is not a string. ... >> methods from the wire transport. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • my first Tck/Tk program... and an XML question
    ... program which takes an XML Schema file, ... a basic XML tree and allows the user to save it. ... proc open_schema { ...
    (comp.lang.tcl)
  • RE: Data Insertion
    ... >The physical database structure is already in place. ... >I can determine the XML file and whether it contains a schema. ... In this particular case XML Schema is used to create a DataSet schema (set ... you're probably wondering how it's possible to load XML without XML ...
    (microsoft.public.dotnet.framework.compactframework)