Hi there,
What is the best way to serialize unknown data?
I have a class that contains a list of parameter objects.
The parameter has a value which can be a simple value of a complex class,
e.g.
class param {
object value;
}
When serializing, I must always have the same name for the value element.
I've looked at 2 approaches:
1) Value is of type object. XmlSerializer MUST know the object's type.
2) Value is of type XmlElement. XmlSerializer doesn't care about content.
Which is better?
1 is easy but has a limitation, 2 is more work.
In addition, the receiver of the xml does not understand type definitions
(it will generate an error) so I cannot have these in my xml.
Does this limit my possibilities to XmlElement IF I want to Deserialize the
same xml?
Any help appreciated,
Michel 5 2654
Michel,
You could inspect the type of the value property and dynamically create an
XmlSerializer instances for every type. You can declare the type and the
element name dynamically using the XmlSerializer constructor that takes an
XmlAttributeOve rrides parameter.
However, constructing an XmlSerializer is a pretty expensive operation, so
this approach carries a lot of overhead if the types are completely random
and don't repeat. I am assuming though, that it's not completely random,
since you're application can only know so many types. Is there a reason you
can't just add A LOT of XmlElement attributes to the class, either at
compile time or using the XmlAttributeOve rrides parameter?
If you're really working with completely arbitratry XML then typing the
property as XmlElement is the best way to go.
--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor
"Michel" <ms*@virtualsci ences.nl> wrote in message
news:c0******** **@reader10.wxs .nl... Hi there,
What is the best way to serialize unknown data? I have a class that contains a list of parameter objects. The parameter has a value which can be a simple value of a complex class, e.g.
class param { object value; }
When serializing, I must always have the same name for the value element.
I've looked at 2 approaches: 1) Value is of type object. XmlSerializer MUST know the object's type. 2) Value is of type XmlElement. XmlSerializer doesn't care about content.
Which is better? 1 is easy but has a limitation, 2 is more work.
In addition, the receiver of the xml does not understand type definitions (it will generate an error) so I cannot have these in my xml. Does this limit my possibilities to XmlElement IF I want to Deserialize
the same xml?
Any help appreciated, Michel
Hi Christoph,
Thanks for your answer.
As you note, there is a limit to the amount of classes I use, so I can tell
XmlSerializer, either run- or compiletime. That is what I do now (I examine
the classes used before creating the XmlSerializer and register them in
XmlSerializer's constructor). Note I use the "object solution" and serialize
only one object (the one that contains all the others).
I think I'll use your argument that XmlSerializer is expensive and stick to
my current solution.
I haven't looked at XmlAttributeOve rrides but I will.
Thanks again,
Michel
"Christoph Schittko [MVP]" <ch************ ********@austin .rr.com> wrote in
message news:eq******** ******@TK2MSFTN GP11.phx.gbl... Michel,
You could inspect the type of the value property and dynamically create an XmlSerializer instances for every type. You can declare the type and the element name dynamically using the XmlSerializer constructor that takes an XmlAttributeOve rrides parameter.
However, constructing an XmlSerializer is a pretty expensive operation, so this approach carries a lot of overhead if the types are completely random and don't repeat. I am assuming though, that it's not completely random, since you're application can only know so many types. Is there a reason
you can't just add A LOT of XmlElement attributes to the class, either at compile time or using the XmlAttributeOve rrides parameter?
If you're really working with completely arbitratry XML then typing the property as XmlElement is the best way to go. -- HTH Christoph Schittko [MVP, XmlInsider] Software Architect, .NET Mentor
"Michel" <ms*@virtualsci ences.nl> wrote in message news:c0******** **@reader10.wxs .nl... Hi there,
What is the best way to serialize unknown data? I have a class that contains a list of parameter objects. The parameter has a value which can be a simple value of a complex
class, e.g.
class param { object value; }
When serializing, I must always have the same name for the value
element. I've looked at 2 approaches: 1) Value is of type object. XmlSerializer MUST know the object's type. 2) Value is of type XmlElement. XmlSerializer doesn't care about
content. Which is better? 1 is easy but has a limitation, 2 is more work.
In addition, the receiver of the xml does not understand type
definitions (it will generate an error) so I cannot have these in my xml. Does this limit my possibilities to XmlElement IF I want to Deserialize the same xml?
Any help appreciated, Michel
Michel,
Note that only the first instantiation of the XmlSerializer is very
expensive. Subsequent ones carry less overhead and you might even be able to
avoid that altogether if you can determine the set of attributes to apply in
the source code or the XmlAttributeOve rrides and keep the XmlSerializer
instance around for the lifetime of your app.
--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor
"Michel" <ms*@virtualsci ences.nl> wrote in message
news:c0******** **@reader08.wxs .nl... Hi Christoph,
Thanks for your answer.
As you note, there is a limit to the amount of classes I use, so I can
tell XmlSerializer, either run- or compiletime. That is what I do now (I
examine the classes used before creating the XmlSerializer and register them in XmlSerializer's constructor). Note I use the "object solution" and
serialize only one object (the one that contains all the others). I think I'll use your argument that XmlSerializer is expensive and stick
to my current solution. I haven't looked at XmlAttributeOve rrides but I will.
Thanks again, Michel
"Christoph Schittko [MVP]" <ch************ ********@austin .rr.com> wrote in message news:eq******** ******@TK2MSFTN GP11.phx.gbl... Michel,
You could inspect the type of the value property and dynamically create
an XmlSerializer instances for every type. You can declare the type and the element name dynamically using the XmlSerializer constructor that takes
an XmlAttributeOve rrides parameter.
However, constructing an XmlSerializer is a pretty expensive operation,
so this approach carries a lot of overhead if the types are completely
random and don't repeat. I am assuming though, that it's not completely random, since you're application can only know so many types. Is there a reason you can't just add A LOT of XmlElement attributes to the class, either at compile time or using the XmlAttributeOve rrides parameter?
If you're really working with completely arbitratry XML then typing the property as XmlElement is the best way to go. -- HTH Christoph Schittko [MVP, XmlInsider] Software Architect, .NET Mentor
"Michel" <ms*@virtualsci ences.nl> wrote in message news:c0******** **@reader10.wxs .nl... Hi there,
What is the best way to serialize unknown data? I have a class that contains a list of parameter objects. The parameter has a value which can be a simple value of a complex class, e.g.
class param { object value; }
When serializing, I must always have the same name for the value element. I've looked at 2 approaches: 1) Value is of type object. XmlSerializer MUST know the object's type. 2) Value is of type XmlElement. XmlSerializer doesn't care about content. Which is better? 1 is easy but has a limitation, 2 is more work.
In addition, the receiver of the xml does not understand type definitions (it will generate an error) so I cannot have these in my xml. Does this limit my possibilities to XmlElement IF I want to
Deserialize the same xml?
Any help appreciated, Michel
Hi Christoph,
Thanks for pointing this out.
The only question I have about this is, the client of my COM object is an
asp site.
My asp knowledge is pretty slim, but my guess is different requests live in
different threads.
So, if I have a shared XmlSerializer object, do I need to make the calls to
it thread safe?
Thanks,
Michel
"Christoph Schittko [MVP]" <ch************ ********@austin .rr.com> wrote in
message news:us******** ******@TK2MSFTN GP12.phx.gbl... Michel,
Note that only the first instantiation of the XmlSerializer is very expensive. Subsequent ones carry less overhead and you might even be able
to avoid that altogether if you can determine the set of attributes to apply
in the source code or the XmlAttributeOve rrides and keep the XmlSerializer instance around for the lifetime of your app.
-- HTH Christoph Schittko [MVP, XmlInsider] Software Architect, .NET Mentor
"Michel" <ms*@virtualsci ences.nl> wrote in message news:c0******** **@reader08.wxs .nl... Hi Christoph,
Thanks for your answer.
As you note, there is a limit to the amount of classes I use, so I can tell XmlSerializer, either run- or compiletime. That is what I do now (I examine the classes used before creating the XmlSerializer and register them in XmlSerializer's constructor). Note I use the "object solution" and serialize only one object (the one that contains all the others). I think I'll use your argument that XmlSerializer is expensive and stick to my current solution. I haven't looked at XmlAttributeOve rrides but I will.
Thanks again, Michel
"Christoph Schittko [MVP]" <ch************ ********@austin .rr.com> wrote
in message news:eq******** ******@TK2MSFTN GP11.phx.gbl... Michel,
You could inspect the type of the value property and dynamically
create an XmlSerializer instances for every type. You can declare the type and
the element name dynamically using the XmlSerializer constructor that
takes an XmlAttributeOve rrides parameter.
However, constructing an XmlSerializer is a pretty expensive
operation, so this approach carries a lot of overhead if the types are completely random and don't repeat. I am assuming though, that it's not completely
random, since you're application can only know so many types. Is there a
reason you can't just add A LOT of XmlElement attributes to the class, either at compile time or using the XmlAttributeOve rrides parameter?
If you're really working with completely arbitratry XML then typing
the property as XmlElement is the best way to go. -- HTH Christoph Schittko [MVP, XmlInsider] Software Architect, .NET Mentor
"Michel" <ms*@virtualsci ences.nl> wrote in message news:c0******** **@reader10.wxs .nl... > Hi there, > > What is the best way to serialize unknown data? > I have a class that contains a list of parameter objects. > The parameter has a value which can be a simple value of a complex class, > e.g. > > class param { > object value; > } > > When serializing, I must always have the same name for the value element. > > I've looked at 2 approaches: > 1) Value is of type object. XmlSerializer MUST know the object's
type. > 2) Value is of type XmlElement. XmlSerializer doesn't care about content. > > Which is better? > 1 is easy but has a limitation, 2 is more work. > > In addition, the receiver of the xml does not understand type definitions > (it will generate an error) so I cannot have these in my xml. > Does this limit my possibilities to XmlElement IF I want to
Deserialize the > same xml? > > Any help appreciated, > Michel > >
No you don't need do do anything special to make the XmlSerializer thread
safe. It is thread safe as long as you don't register any non-thread-safe
event handlers.
--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor
"Michel" <ms*@virtualsci ences.nl> wrote in message
news:c0******** **@reader08.wxs .nl... Hi Christoph,
Thanks for pointing this out. The only question I have about this is, the client of my COM object is an asp site. My asp knowledge is pretty slim, but my guess is different requests live
in different threads. So, if I have a shared XmlSerializer object, do I need to make the calls
to it thread safe?
Thanks, Michel
"Christoph Schittko [MVP]" <ch************ ********@austin .rr.com> wrote in message news:us******** ******@TK2MSFTN GP12.phx.gbl... Michel,
Note that only the first instantiation of the XmlSerializer is very expensive. Subsequent ones carry less overhead and you might even be
able to avoid that altogether if you can determine the set of attributes to
apply in the source code or the XmlAttributeOve rrides and keep the XmlSerializer instance around for the lifetime of your app.
-- HTH Christoph Schittko [MVP, XmlInsider] Software Architect, .NET Mentor
"Michel" <ms*@virtualsci ences.nl> wrote in message news:c0******** **@reader08.wxs .nl... Hi Christoph,
Thanks for your answer.
As you note, there is a limit to the amount of classes I use, so I can tell XmlSerializer, either run- or compiletime. That is what I do now (I examine the classes used before creating the XmlSerializer and register them
in XmlSerializer's constructor). Note I use the "object solution" and serialize only one object (the one that contains all the others). I think I'll use your argument that XmlSerializer is expensive and
stick to my current solution. I haven't looked at XmlAttributeOve rrides but I will.
Thanks again, Michel
"Christoph Schittko [MVP]" <ch************ ********@austin .rr.com>
wrote in message news:eq******** ******@TK2MSFTN GP11.phx.gbl... > Michel, > > You could inspect the type of the value property and dynamically create an > XmlSerializer instances for every type. You can declare the type and the > element name dynamically using the XmlSerializer constructor that takes an > XmlAttributeOve rrides parameter. > > However, constructing an XmlSerializer is a pretty expensive operation, so > this approach carries a lot of overhead if the types are completely random > and don't repeat. I am assuming though, that it's not completely random, > since you're application can only know so many types. Is there a reason you > can't just add A LOT of XmlElement attributes to the class, either
at > compile time or using the XmlAttributeOve rrides parameter? > > If you're really working with completely arbitratry XML then typing the > property as XmlElement is the best way to go. > -- > HTH > Christoph Schittko [MVP, XmlInsider] > Software Architect, .NET Mentor > > "Michel" <ms*@virtualsci ences.nl> wrote in message > news:c0******** **@reader10.wxs .nl... > > Hi there, > > > > What is the best way to serialize unknown data? > > I have a class that contains a list of parameter objects. > > The parameter has a value which can be a simple value of a complex class, > > e.g. > > > > class param { > > object value; > > } > > > > When serializing, I must always have the same name for the value element. > > > > I've looked at 2 approaches: > > 1) Value is of type object. XmlSerializer MUST know the object's type. > > 2) Value is of type XmlElement. XmlSerializer doesn't care about content. > > > > Which is better? > > 1 is easy but has a limitation, 2 is more work. > > > > In addition, the receiver of the xml does not understand type definitions > > (it will generate an error) so I cannot have these in my xml. > > Does this limit my possibilities to XmlElement IF I want to Deserialize > the > > same xml? > > > > Any help appreciated, > > Michel > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael |
last post by:
Hi
I anyone have a clue or can solve my problem I would be
glad :-) Regards Michael
I have a problem with creating an XML-document where the
returning data from the webservice, have been serialized.
In my program I am calling a webservice which then return
the data to the calling program. The program then have to
serialize the data and create an XML-document.
|
by: vince |
last post by:
Can I add (append) to an xml file that already contains a
serialized object, and be able to deserialize to either
or both objects from the same file...??? How is this
done...??
thanks,
vince
|
by: |
last post by:
In the beginning we had Ini files.
Later we had registery files.
Now have xml files and our read-only myapp.config file.
My question now, is what is the best way to store and load user and machine
specific settings for a .NET program?
And what classes, or code do we have to do this in C#?
I don't think that using the myapp.config is the best choice to store since
the file might be read-only if the program is started from a CD ROM, or...
|
by: MrNobody |
last post by:
I was a Java developer so I'm used to using property files as a means to keep
configuration settings for my apps. I'm wondering what options are there with
..NET?
Some settings I want to include are like a root directory for a target
program on the user's machine my app uses, which they would be prompted to
supply at startup. Normally the registry is used for this but I'd rather not
use the registry if possible. Isn't there some kind of...
|
by: js |
last post by:
Does anybody knows how to solve the problem? I added
attribute to the following classes in
Microsoft.Practices.EnterpriseLibrary.Data namespace, but I still get
the error. Thanks.
Database.cs
DatabaseFactory.cs
DatabaseProviderFactory.cs
DBCommandWrapper.cs
| |
by: Ariana |
last post by:
I have the following situation for an ASP.NET 2.0 web site:
- Data is in one XML file
- I want to transform the data using an XSLT file before using it
- The data is hierarchical
- The data will change only occasionally but is quite large and needs
to be up to date when it does change
- The data will be used to display information in a standard format on
every page, but will be filtered on different pages
|
by: =?Utf-8?B?Qnlyb24=?= |
last post by:
When I try to serialize an instance of the LocationCell below (note Building
field) I get an error in the reflection attempt. If I remove the _Building
field it serializes fine. I tried renaming Building._Name to Building._BName
in case the duplicate name was the issue, but that didn't help.
Is there a native way to serialize nested objects, or will I have to write
my own?
public class LocationCell
|
by: FFMG |
last post by:
Hi,
I would like to add international support for my site to allow some of
my users to translate the site if they really feel the urge to do it.
I don't use any CMS, the site was developed, (and refined :)), by me.
But I see that various CMSs handle languages very differently.
Joomla! for example has a smallish define file that has all the
translations.
Wordress on the other hand seems to have a function __(...) that is
|
by: Brian |
last post by:
HI, I have two sets of data, the largest set of data contains 370 rows...
both sets only have two columns. I want to be able to distribute the data
with my applaction. The other option, would be to have the data as seprate
file(easier if needs updating), but I don't what the user to be able to read
the file, just my program should be able to read the file.
Any ideas on the best method?
thanks,
Brian
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |