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

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 32224

"Marek" <no****@nospam.com> wrote in message
news:Km*********************@news20.bellglobal.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*********************@news20.bellglobal.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
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...
5
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...
6
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...
4
by: nsj | last post by:
How shall i use quotation marks within another in asp.net?
1
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" ...
3
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...
5
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.