473,394 Members | 1,787 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,394 software developers and data experts.

Inheriting from XSDObjectGen classes and XmlSerialize

Hi,

I'm just getting used to XSDObjectGen and i have the following question.
Can i use a class inherited from a class generated by XSDObjectGen with
XmlSerialize?

Specifically, I have many xml files arriving from a PC inventory scanner we
use.
I wish to deserialize them and then process them.

I've used XSDObjectGen and XmlSerialize.Deserialize to do this, and it
works really well.

However, for the next step I want to create a set of classes that provide
functionality on top of the class produced by XmlSerialize.Deserialize.

I could create these classes and make the XSDObjectGen generated class a
private memeber, but I'd prefer to inherit from the generated class.

Whenever i try to do this, i get exceptions from XmlSerialize.Deserialize.

The code that works is below

XmlSerializer s = new XmlSerializer(typeof(HatLib.HatXml.ScanData));
HatLib.HatPc scanData = (HatLib.HatXml.ScanData)s.Deserialize(new
XmlTextReader(fileName));

However, when i create a class as follows

public class HatPc : HatLib.HatXml.ScanData
{
public HatPc()
{
}
// Specific code here

}

I can't use this class with XmlSerialize.Deserialize. I've tried many
combinations of casting etc to see if i can make it work, but to no avail.

Any suggestions?

Thanks

Nov 12 '05 #1
2 2209
You have to be careful with Inheritance and the XmlSerializer.

You have to instantiate the XmlSerializer instance for the derived type,
not the base type. However, you can't deserialize the XML documents of
your base type with that serializer any longer as that serializer
expects a different root element for the derived type.

You're much better off not changing the generated classes or deriving
from them when you need to work with the XmlSerializer. Can you design
classes to operate on the serialization classes instead?

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

-----Original Message-----
From: Peter Bates [mailto:Pe********@discussions.microsoft.com]
Posted At: Sunday, January 23, 2005 6:05 PM
Posted To: microsoft.public.dotnet.xml
Conversation: Inheriting from XSDObjectGen classes and XmlSerialize
Subject: Inheriting from XSDObjectGen classes and XmlSerialize

Hi,

I'm just getting used to XSDObjectGen and i have the following question. Can i use a class inherited from a class generated by XSDObjectGen with XmlSerialize?

Specifically, I have many xml files arriving from a PC inventory scanner we
use.
I wish to deserialize them and then process them.

I've used XSDObjectGen and XmlSerialize.Deserialize to do this, and it works really well.

However, for the next step I want to create a set of classes that provide functionality on top of the class produced by XmlSerialize.Deserialize.
I could create these classes and make the XSDObjectGen generated class a private memeber, but I'd prefer to inherit from the generated class.

Whenever i try to do this, i get exceptions from XmlSerialize.Deserialize.
The code that works is below

XmlSerializer s = new XmlSerializer(typeof(HatLib.HatXml.ScanData));
HatLib.HatPc scanData = (HatLib.HatXml.ScanData)s.Deserialize(new
XmlTextReader(fileName));

However, when i create a class as follows

public class HatPc : HatLib.HatXml.ScanData
{
public HatPc()
{
}
// Specific code here

}

I can't use this class with XmlSerialize.Deserialize. I've tried many
combinations of casting etc to see if i can make it work, but to no avail.
Any suggestions?

Thanks


Nov 12 '05 #2
Yeah,
After looking at it a bit harder I've decided to just construct classes that
hold the deserialized class as a private member.

much easier.

thanks for confirming that.

"Christoph Schittko [MVP]" wrote:
You have to be careful with Inheritance and the XmlSerializer.

You have to instantiate the XmlSerializer instance for the derived type,
not the base type. However, you can't deserialize the XML documents of
your base type with that serializer any longer as that serializer
expects a different root element for the derived type.

You're much better off not changing the generated classes or deriving
from them when you need to work with the XmlSerializer. Can you design
classes to operate on the serialization classes instead?

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

-----Original Message-----
From: Peter Bates [mailto:Pe********@discussions.microsoft.com]
Posted At: Sunday, January 23, 2005 6:05 PM
Posted To: microsoft.public.dotnet.xml
Conversation: Inheriting from XSDObjectGen classes and XmlSerialize
Subject: Inheriting from XSDObjectGen classes and XmlSerialize

Hi,

I'm just getting used to XSDObjectGen and i have the following

question.
Can i use a class inherited from a class generated by XSDObjectGen

with
XmlSerialize?

Specifically, I have many xml files arriving from a PC inventory

scanner
we
use.
I wish to deserialize them and then process them.

I've used XSDObjectGen and XmlSerialize.Deserialize to do this, and

it
works really well.

However, for the next step I want to create a set of classes that

provide
functionality on top of the class produced by

XmlSerialize.Deserialize.

I could create these classes and make the XSDObjectGen generated

class a
private memeber, but I'd prefer to inherit from the generated class.

Whenever i try to do this, i get exceptions from

XmlSerialize.Deserialize.

The code that works is below

XmlSerializer s = new XmlSerializer(typeof(HatLib.HatXml.ScanData));
HatLib.HatPc scanData = (HatLib.HatXml.ScanData)s.Deserialize(new
XmlTextReader(fileName));

However, when i create a class as follows

public class HatPc : HatLib.HatXml.ScanData
{
public HatPc()
{
}
// Specific code here

}

I can't use this class with XmlSerialize.Deserialize. I've tried many
combinations of casting etc to see if i can make it work, but to no

avail.

Any suggestions?

Thanks


Nov 12 '05 #3

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

Similar topics

0
by: Burak | last post by:
Hello, I am working on a VB.NET web service that will be used to send and receive job openings. I would like to use their "industry standard" xsd file ...
2
by: Pavan | last post by:
Hi, I received an error from a schema using the much hyped XSDObjectGen: Unexpected error occured in XSDObjectGen : Specified cast is not valid. Please send the schema to support. However...
3
by: Bobby | last post by:
I have a schema and have used XSDObjectGen.exe to create a set of classes that represent the schema. What is the best way to fill xsdobjectgen.exe generated classes with data? I want to create...
3
by: Edward Clements | last post by:
I'm looking for a good tool to generate C# classes (from XSD-schemas) to (de-)serialize XML corresponding to those schemas. XSDObjectGen almost meets these requirements -- only, I need to...
1
by: SteveC | last post by:
I've used XsdObjectGen (1.36) to create some C# classes, all seemed fine Deserialized some test XML into the class, again seemed to work Ok, but then I noticed that any of the DateTime...
0
by: Pascal Brunot | last post by:
Hi, Running XSDObjectGen (1.4.1.0) on the following Infopath-generated XSD gives an "unexpected error": "Event register full" during generation (exact english error message may differ, i am...
0
by: William | last post by:
Does anyone know the pros and cons of using xsd.exe vs. XsdObjectGen.exe for generating strongly-typed C# classes for web services? I tried both for a version 2.3.2 of industry standard MISMO Flood...
0
by: Jeff Killberg | last post by:
I am working on a .NET 2.0 project where we will be defining a large object model in XML schema and generating the C# code to process XML documents conforming to this XML schema into the object...
1
by: Veerle | last post by:
Hi, I am experiencing a lot of problems with XsdObjectGen. I downloaded the latest version from...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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,...
0
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...
0
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...

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.