473,734 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to implement IXMLSerializabl e

I have a complex class heirarchy where all of my classes inherit from a
single base class (BaseObject) and this BaseObject class inherits from
XPBaseObject. XPBaseObject is a 3rd party base class from Express
Persistent Objects (XPO) from DevExpress. It looks kind of like
this...

BaseObject - (inherits XPBaseObject)

UserCase - (root object in my heirarchy - inherits from BaseObject)
- UserCase has many properties, some of which are other objects,
UserCase also has collections of other objects. All complex objects
inherit from BaseObject also

I want to use XML serialization so that I can save a UserCase object
(and all of it's properties and collecitons) to an XML file and then
later repopulate it in my application. Unfortunately XPBaseObject does
not support serialization. I have been in contact with tech support at
DevExpress and have been told that if I just implement the
IXMLSerializabl e interface in my BaseObject class then the
serialization should work fine.

So it looks like all I need to do is implement the follow items:
WriteXML(), ReadXML(), and GetSchema(). [I am using .NET v1.1]

I have implemented WriteXML and it works fine. I was able to write a
generic WriteXML method for my base class that examines the properties
and uses recursion to write out a nice XML file. I used custom
attributes on my properties for my different classes to determine if
they need to be written to the XML file or not. (Some properties are
read only and don't need to be written to the XML file).

But now I am stuck and not sure what I should do next. The tech
support person at DevExpress has told me that the only other thing I
need to do is implement GetSchema and it should work - I don't need to
implement anything for ReadXML. However I have read other posts at
other web sites that say that I should implement ReadXML so that my
classes know how to convert the XML file back to an object. I am
looking for a little help in understanding exactly how this XML
deserialization works. Does .NET use the schema to figure out how to
populate the object with data from the XML file? I can't figure out
how to write a generic GetSchema method for my base class that will
work correctly. Can anyone help me maybe with some pseudo code? I can
post some code snippets if that would help.

Thanks,
Corey

Jan 18 '06 #1
1 8695

Corey,

I think that it depends if you want to use automatic .net xml
serialization features (invoked by the framework, for example, when you
use your object with .NET remoting).
In this case, you have to implement the entire IXmlSerializabl e.
Instead, if you only need the code for writing and reading xml by your
own, you don't need to implement GetSchema(). Simply implement
WriteXml() and ReadXml(), but your class cannot be used automatically
by the framework.

You can take a look to ADCG tool (http://www.codetools.it),
it is an automatic C# code generator, that also automatically
implements IXmlSerializabl e interface.
You can find an useful example reading the classese generated by the
tool.

Chrjs.

--
chrjs
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Feb 3 '06 #2

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

Similar topics

1
831
by: Peter Nofelt | last post by:
Hey All, I am having issue with serializing a class and its base class using ..net 2.0. I am using IXmlSerializable I've provided code displaying my at the bottom of this post. Thanks ahead of time for any help or feedback. Cheers, Peter
3
4996
by: John Glover | last post by:
To whoever can help, I've been having a problem with XML deserialization lately. I needed to serialize and deserialze two objects which inherited from Hashtable. Because IDictionary implementations cannot be serialized, I had to take matters into my own hands by implementing a wrapper over the Hashtable which implemted IXmlSerializable. I called it XmlHashtable. It has, among other convenience methods, a method
0
1516
by: Marek | last post by:
Hi I have an object model which includes a Dictionary<> property which I am trying to serialize/deserialize using IXmlSerializable as follows class X:IDictionary<a,b>,IXmlSerializable) What is happening is that the objects get persisted fine (checked using notepad) and I can step through the WriteXml routine using the debugger. However when trying to deserialize, my ReadXml routine is just not being called - break points in the...
0
3185
by: Jamie | last post by:
I've implemented 3 classes, all of which make use of the IXmlSerializable interface. Class A has 2 properties that are instances to class B and C. Class A - serialization routine: public void WriteXml(XmlWriter writer) { writer.WriteAttributeString("test1",test1);
0
2831
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass magic, I wrote the following module. It is mainly useful as a light weight tool to help programmers catch mistakes at definition time (e.g., forgetting to implement a method required by the given interface). This is handy when unit tests or...
0
1627
by: burningmidget | last post by:
I am having trouble using IXmlSerializable within a base class and having xsi:type work correctly when deserializing an xml file. Here is a very simplified version of the what is going on in the code: public class BaseJunkClass : IXmlSerializable { public void ReadXml(XmlReader Reader) { } public void WriteXml(XmlWriter Writer) { }
2
1827
by: sachy | last post by:
Hello All, I want to deserialize part of xml into a object. For this i am having class that implements the IXmlSerializable interface. For this class i get the xmlnode object that has the xml. How do i read this xmlnode object in the readxml of IXmlSerializable ? as the ReadXml has the xmlreader object as as input. How do i associate the xmlreader to xmlnode so that i can go ahead with reader.read().
0
1835
by: valentin tihomirov | last post by:
I wanted to transfer some binary data to my Web Service. There is an example: Yasser Shohoud -- "Web services and large content in .NET 2.0" @ http://blogs.msdn.com/yassers/archive/2004/11/10/255212.aspx It seems that the demo code is a part of some Web Service, since I see the DownloadSong() method has the attribute. The problem is to obtain the SongStream schema, which is required to generate the proxy. Normally, the Web Service...
5
2657
by: Tony Johansson | last post by:
Hello! The only reason I can see interface to be implemented explicitly is when the a class implement two interface having the same method signature. In all other cases I can implement interface implicitlly. Can you agree with me about this statement ? //Tony
0
8946
marktang
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...
0
8776
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
9449
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...
1
9236
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,...
0
9182
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
6735
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
4550
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
3261
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
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.