473,225 Members | 1,361 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,225 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 2205
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.