473,595 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>
...
<WeirdElementCo ntainer>
<WeirdElement >
</WeirdElement>
</WeirdElementCon tainer>
</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.Seri alization.XmlIn clude(typeof(No tSoWeirdElement ))]
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(t ypeof(Root));

[System.Xml.Seri alization.UseXm lSerializer(typ eof(MyWeirdElem entSerializer))]
public class WeirdElement
{
}

xs.Serialize(my RootObject);

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>>
Nov 12 '05 #1
1 2078
All,

Just a follow-up on how I did manage to solve this problem, for all you out
there who need to solve a similar problem.

I did the following:

I created a number of classes:
- A Generic Parser class which handles the serialization.
- A custom attribute which contains a mapping to Schema name and version.
- A base 'WeirdElementCl ass' which can be inherited from

In the Generic Parser class I handle the UnknownElement event from the
serializer, since the container class does contain the base
'WeirdElementCl ass' but it is marked with the XmlIgnore attribute. In this
event I check for the correct element, just to be sure. Then I use
reflection to find the specific schema / verion attribute which I attached
to the correct 'WeirdElementCl ass'. When found I can deserialize this class
and add its instance to the property to the container class.

Serializing is pretty straight forward, after serializing the Root object to
an XmlDocument I can manually serialize the 'WeirdElementCl ass' and add it
to the xml at the correct location.

If anyone wants to know more, please let me know.

Ivo Bronsveld

"Ivo Bronsveld" <no************ **@bts.net> wrote in message
news:Oc******** ******@TK2MSFTN GP10.phx.gbl...
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>
...
<WeirdElementCo ntainer>
<WeirdElement >
</WeirdElement>
</WeirdElementCon tainer>
</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.Seri alization.XmlIn clude(typeof(No tSoWeirdElement ))]
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(t ypeof(Root));

[System.Xml.Seri alization.UseXm lSerializer(typ eof(MyWeirdElem entSerializer))]
public class WeirdElement
{
}

xs.Serialize(my RootObject);

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>>

Nov 12 '05 #2

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

Similar topics

0
1445
by: MicFra | last post by:
hi, i got a little problem with pdf-serializing after updating from cocoon 2.1.2 to 2.1.4. following scenario: - using serializer org.apache.cocoon.serialization.FOPSerializer, with name fo2pdf and mime-type application/pdf - using it in
1
12629
by: Christopher Pragash | last post by:
Hello all, I'm trying to persist an object of type Arraylist into XML using the following the XMLSerializer and it returns an "Unknown" Error. I'm able to serialize and deserialize the arraylist object using Binary format but unable to do so using XML formatter. Is it possible to serialize an ArrayList object into XML? If somebody could pass on some sample code that would be really great. Thanks,
2
1618
by: Chris Smith | last post by:
I bet this question has been asked quite a bit, but if someone can point me in the right direction, I would be very grateful. I would like to write a assembly (dll) that one of the functions will act as a task router. This router will take different objects of many types, and pass that object to the correct webservice for handling. Seems that doing this creates quite a bit of serialization issues, especially when the webservice returns a...
4
5405
by: John Vottero | last post by:
When a class contains a TimeSpan property, XmlSerializer doesn't work. A TimeSpan property is serialized like: <MySpan /> I've read a number of posts that talk about why this happens and how to work around it. My question is from a slightly different angle. What can I do to my value type structures so that XmlSerializer can serialize them properly?
2
3514
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: + More ways to contact me __________________________________________________________________
4
3614
by: Dave Veeneman | last post by:
When does serializing objects make more sense than persisting them to a database? I'm new to object serialization, and I'm trying to get a feel for when to use it. Here is an example: I'm writing an accounting application. I have a chart of accounts in the form of a containment hierarchy. A GeneralLedger contains a number of Accounts, and each of these Accounts can contain a Aubledger, which contains its own Accounts, and so on. The...
0
1229
by: rein.petersen | last post by:
Hi All, I've been working on a means to create dynamic asemblies (modules actually) from parsing XSD schemas which creates a perfect .net representation of the schema at hand (dynamically). My next hurdle is to deserialize xml documents (that conform to the schemas from which dynamic modules were derived) to the types from the dynamic module.
47
3095
by: Max | last post by:
Due to the behaviour of a particular COM object, I need to ensure that a request for a particular ASP page is finalized before another request for the page is processed. Does IIS have a way to ensure that subsequent requests will be queued until the current request is completed? If not, can IIS be configured to use seperate processes to satisfy requests for a nominated ASP page? Thanks in advance.
3
2116
by: Jeremy | last post by:
I've created a serializable class and put attributes around all the properties that should be serialized. I return the class from a web service, but my problem is that the wsdl for the web service is only including the Values poperty, and nothing else. Also, when the object gets serialized out, only the Values property gets serialized. I can't figure out why. I've included the serialized output from the webservice and the class code...
0
7883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8262
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8252
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5839
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5421
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3875
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2391
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1491
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.