473,729 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.De serialize 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.De serialize.

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.De serialize.

The code that works is below

XmlSerializer s = new XmlSerializer(t ypeof(HatLib.Ha tXml.ScanData)) ;
HatLib.HatPc scanData = (HatLib.HatXml. ScanData)s.Dese rialize(new
XmlTextReader(f ileName));

However, when i create a class as follows

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

}

I can't use this class with XmlSerialize.De serialize. 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 2232
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.publi c.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.De serialize 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.De serialize.
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.De serialize.
The code that works is below

XmlSerializer s = new XmlSerializer(t ypeof(HatLib.Ha tXml.ScanData)) ;
HatLib.HatPc scanData = (HatLib.HatXml. ScanData)s.Dese rialize(new
XmlTextReader(f ileName));

However, when i create a class as follows

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

}

I can't use this class with XmlSerialize.De serialize. 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.publi c.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.De serialize 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.De serialize.

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.De serialize.

The code that works is below

XmlSerializer s = new XmlSerializer(t ypeof(HatLib.Ha tXml.ScanData)) ;
HatLib.HatPc scanData = (HatLib.HatXml. ScanData)s.Dese rialize(new
XmlTextReader(f ileName));

However, when i create a class as follows

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

}

I can't use this class with XmlSerialize.De serialize. 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
1384
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 http://ns.hr-xml.org/2_2/HR-XML-2_2/StandAlone/PositionOpening.xsd which specifies the formatting for job openings.
2
2290
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 xsd.exe (.NET v1.1) worked ok (did'nt give an error). I wonder how long we'll have to wait before we get a stable and comprehensive conversion from schema to class.
3
4451
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 and serialize an instance of one of the classes in this schema. the class is declared publicly, but isn't accessible outside the namespace: ...
3
4744
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 generate a ..cs file for each common .xsd file that is included (xsd:include) -- there are a lot schemas which include several common .xsd files (full schema at http://www.witsml.org/schemas/WITSML120_2003-01-30.zip). The "/s" switch would have beein...
1
1300
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 properties of the class which didn't have a value in the XML were returning a value of "now" I tried the dataset class that VS2003 generates, and that is able to handle the null date-times
0
1840
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 using the italian version). VS.net 2003 accepts the XSD. The strange thing is that I managed using XSDObjectGen on much more
0
2232
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 documents (a fairly complex standard found on http://mismo.org/current%20specs/currentstandardlist.html) and it appears that xsd.exe did a better job, but I may be missing something.
0
2994
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 model. On a similar project, we used XsdObjectGen.exe. I am trying to determine if there are major enough reasons to use XsdObjectGen or if the .NET 2.0 version of Xsd.exe will suffice. Our XML schema will be defined using a fairly minimal set...
1
4345
by: Veerle | last post by:
Hi, I am experiencing a lot of problems with XsdObjectGen. I downloaded the latest version from http://www.microsoft.com/downloads/details.aspx?FamilyID=89e6b1e5-f66c-4a4d-933b-46222bb01eb0&DisplayLang=en but this is dated september 2006, so it's not very recent. We receive xsds from a third party and our application has to generate xml that is valid for these xsds. This makes that we cannot alter the xsds in any way, we have to...
0
8925
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
8763
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
9428
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...
0
9288
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9206
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
9154
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...
0
4531
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
3240
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
2166
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.