473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to implement IXMLSerializable

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

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 IXmlSerializable.
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 IXmlSerializable 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
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...
3
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...
0
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...
0
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...
0
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...
0
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...
2
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. ...
0
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" @...
5
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.