473,225 Members | 1,307 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.

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 32207

"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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
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...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
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...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.