473,748 Members | 3,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# code generation with xsd.exe "how to ?"

Actually, the very first question I should ask is "does it make sense at
all?".
For 2 days I've been trying to generate C# classes using XML schema and
xsd.exe tool. So far the results are not exciting but I assume I am
seriously short of knowledge, so here I am - asking for help. My current
situation is that I can define schemas that will generate very simple
classes but I have two major problems:

(1) I do not know how to write a schema, so that my classes can get
properties with skeletons for getter and setter, as opposed to public fields
? Right now, for every generated class, all the attributes defined in xsd,
get converted into public fields, not properties.

(2) How to write a schema to get class structure that exposes inheritance
and incorporates interfaces ?
I try to use "complexContent " with "extension" and "base" attributes but
when compiling the schema with xsd.exe I am getting different kind of errors
(i.e. "cannot generate classes because no top-level elements with complex
type were found" or "cannot generate classes because no top-level elements
with complex type were found" ). I even tried to compile an example from
MSDN (Person->ExtendedPerson ) but no success at all...

My friend is strongly advocating gsl-gen (a third-party code generator) but
I would really like to be able getting that work done using .net
infrastructure, without any additional pieces.
I would appreciate any useful hints, especially some exmaples for my two
problems that I mentioned above. Thank you very much,

Marek
Nov 12 '05 #1
2 32313

"Marek" <no****@nospam. com> wrote in message
news:Km******** *************@n ews20.bellgloba l.com...
Actually, the very first question I should ask is "does it make sense at
all?".
For 2 days I've been trying to generate C# classes using XML schema and
xsd.exe tool. So far the results are not exciting but I assume I am
seriously short of knowledge, so here I am - asking for help. My current
situation is that I can define schemas that will generate very simple
classes but I have two major problems:

(1) I do not know how to write a schema, so that my classes can get
properties with skeletons for getter and setter, as opposed to public fields ? Right now, for every generated class, all the attributes defined in xsd,
get converted into public fields, not properties.

xsd.exe generates public fields. If you like you can take the generated
code and modify it. For example,
http://www.winisp.net/cheeso/srcview...file=Morpho.cs
You can also try XsdObjectGen - see
http://hyperthink.net/blog/default,date,2004-04-29.aspx

(2) How to write a schema to get class structure that exposes inheritance
and incorporates interfaces ?
I try to use "complexContent " with "extension" and "base" attributes but
when compiling the schema with xsd.exe I am getting different kind of errors (i.e. "cannot generate classes because no top-level elements with complex
type were found" or "cannot generate classes because no top-level elements with complex type were found" ). I even tried to compile an example from
MSDN (Person->ExtendedPerson ) but no success at all...

Why don't you try going the other direction? Build your object class, then
run xsd.exe on the resulting assembly (dll or exe or ..) and then examine
the inferred schema.

My friend is strongly advocating gsl-gen (a third-party code generator) but I would really like to be able getting that work done using .net
infrastructure, without any additional pieces.
I would appreciate any useful hints, especially some exmaples for my two
problems that I mentioned above. Thank you very much,

Marek

Nov 12 '05 #2
1) You don't need to use third party software to get public properties or
strong typed collections instead of arrays. Check the article titled Code
Generation in the .NET Framework Using XML Schema on MSDN
(http://msdn.microsoft.com/xml/defaul...s/dnxmlnet/htm
l/xsdcodegen.asp) .
Another quick trick you can use is this:
http://weblogs.asp.net/cazzu/archive.../26/25460.aspx

2) In order to get classes that inherit from others, you have to create
complex types that act as the base type for others. For example, you have to
define a Person complex type, and make the ExtendedPerson complex type
inherit from it. You'll get two classes, the later inheriting the former.

--
Daniel Cazzulino [MVP XML]
Clarius Consulting SA
http://weblogs.asp.net/cazzu
http://aspnet2.com
"Marek" <no****@nospam. com> wrote in message
news:Km******** *************@n ews20.bellgloba l.com...
Actually, the very first question I should ask is "does it make sense at
all?".
For 2 days I've been trying to generate C# classes using XML schema and
xsd.exe tool. So far the results are not exciting but I assume I am
seriously short of knowledge, so here I am - asking for help. My current
situation is that I can define schemas that will generate very simple
classes but I have two major problems:

(1) I do not know how to write a schema, so that my classes can get
properties with skeletons for getter and setter, as opposed to public fields ? Right now, for every generated class, all the attributes defined in xsd,
get converted into public fields, not properties.

(2) How to write a schema to get class structure that exposes inheritance
and incorporates interfaces ?
I try to use "complexContent " with "extension" and "base" attributes but
when compiling the schema with xsd.exe I am getting different kind of errors (i.e. "cannot generate classes because no top-level elements with complex
type were found" or "cannot generate classes because no top-level elements with complex type were found" ). I even tried to compile an example from
MSDN (Person->ExtendedPerson ) but no success at all...

My friend is strongly advocating gsl-gen (a third-party code generator) but I would really like to be able getting that work done using .net
infrastructure, without any additional pieces.
I would appreciate any useful hints, especially some exmaples for my two
problems that I mentioned above. Thank you very much,

Marek

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.708 / Virus Database: 464 - Release Date: 19/06/2004
Nov 12 '05 #3

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

Similar topics

5
119586
by: siliconmike | last post by:
On many websites they have a blurred image with a code which you're supposed to reenter in a text box to validate your form submission. How do I implement such a thing using php? Apart from preventing automatic form submission by any malicious robot, does this serve any other purpose? Mike
5
5677
by: apple | last post by:
UDBV8 fp 6a - AIX 5.1 We have scheduled cron jobs to do backups. Periodically and starting to occur more frequently, a backup fails with this error: SQL2072N Unable to bind the shared library "". Reason code: "". We are backing up to a file system on the server. Can't find anything in the logs. We can manually resubmit the job 15 or 30 minutes later and everything works fine. Any ideas on what might be happening? The documentation on...
6
26476
by: Wito | last post by:
hi, I want to backup database (db2, aix 5.1) using script. When I exec script logging to user db2inst1 then is everything ok, but from cron, I get these error: SQL10007N Message "-1390" could not be retrieved. Reason code: "6". Where is the problem?
4
4842
by: nsj | last post by:
How shall i use quotation marks within another in asp.net?
1
1352
by: eewwttww | last post by:
how to show the "txt code" that the WebBrowser wont to save when he wont to save html+pictures with the "dialogbox" - before saving. this is the code to open the save "dialogbox" Me.WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_PROMPTUSER, 0, 0 this is not good for me: Text1.Text = WebBrowser1.Document.documentElement.OuterHTML
3
12015
by: nan | last post by:
Hi All, I am trying to connect the Database which is installed in AS400 using DB2 Client Version 8 in Windows box. First i created the Catalog, then when i selected the connection type as ODBC, then i am getting
5
3231
by: Andy B | last post by:
I am making a web application that would randomly create an activation code and put it in a database. The web application would then send it in an email to the user with a link to go to and enter the activation code. How would I do this? and what sql server data type would I use? I want the activation code to be no longer than 12 characters, have a mix of numbers and letters and have no special symbols.
0
3447
by: Peter Morris | last post by:
When I compile a WinForm app I get the following warning: The file 'C:\Data\CustomerProjects\Inteevo\Projects\AlterEgo\AlterEgo\WizardStepControls\SceneSettingsStepControl.cs' does not support code parsing or generation because it is not contained within a project that supports code. I am a bit confused by this. It's a UserControl within a WinForm app. In what way is this a project that does not support code?
0
8991
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
9544
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
9372
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
9324
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
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4606
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...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.