XSD Class Generation

C

C. J. Lee

Defining a default namespace and target namespace explicitly in each of the included schema definition files resolved the "datatype ... missing" issue. Moreover, if there is a "primary" xsd that includes a set of subset xsds, then referencing both the primary xsd and the subset xsds in the XSD Class Generation command line causes the Schema validation warning, "already been declared". Only the primary xsd should be referenced in the command line.

I encountered these problems using .NET 2.0 XSD Class Generation tool. Does anyone know if this is still an issue using .NET 3.0?
 
J

Jon Procter

I have a large project that has been converted from VB.Net to c#, the VB Project obviously compiled perfectly before the migration, but I'm now getting problems with the c# generated from the .xsd in the area of the connection string

The original InitConnection that was generated from the xsd would look like this (in VB of course):

<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _
Private Sub InitConnection()
Me._connection = New Global.System.Data.SqlClient.SqlConnection
Me._connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("TimeRecordingConnectionString").ConnectionString
End Sub


which worked fine. Now that I have converted the project all to c#, that same method when generated from the xsd looks like this (in c#):

[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
private void InitConnection() {
this._connection = new global::System.Data.SqlClient.SqlConnection();
this._connection.ConnectionString = System.Configuration.ConfigurationManager.Connectionstring["TimeRecordingConnectionString"].ConnectionString;
}


if you notice the generated line:

this._connection.ConnectionString = System.Configuration.ConfigurationManager.Connectionstring["TimeRecordingConnectionString"].ConnectionString;


I get the error:

'System.Configuration.ConfigurationManager' does not contain a definition for 'Connectionstring'


I think the line ought to be more like:

this._connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["TimeRecordingConnectionString"].ConnectionString;


But obviously there is no point in my changing it, as it will be overwritten next time the xsd is generated into the code file. Is there a setting somewhere in my xsd that is likely to be making it create this incorrectly? Is it a versioning thing? (I'm using VS2008, so 3.5). It must be something simple, as it's generating the file, it's just "This is not the c# (droids) we are looking for!"

obviously I can post xsd if required, although it's substantial!

HELP PLEASE!



C. J. Lee wrote:

XSD Class Generation tool
11-Jul-08

Defining a default namespace and target namespace explicitly in each of the included schema definition files resolved the "datatype ... missing" issue. Moreover, if there is a "primary" xsd that includes a set of subset xsds, then referencing both the primary xsd and the subset xsds in the XSD Class Generation command line causes the Schema validation warning, "already been declared". Only the primary xsd should be referenced in the command line.

I encountered these problems using .NET 2.0 XSD Class Generation tool. Does anyone know if this is still an issue using .NET 3.0?

Previous Posts In This Thread:

XSD Class Generation
Hi,

Can someone tell me how to generate classes from XSD files?
Is there an easy way to convert it into typed datasets etc?

Or any other suggestion is welcomed.

--

SevDer
http://www.sevder.com

SevDerClick right on your mouse on the surface in the IDE where the not XML
SevDer

Click right on your mouse on the surface in the IDE where the not XML
presentation of the XSD is located and choose generate dataset.

Cor

"SevDer" <[email protected]> schreef in bericht

xsd.exe (for example, at a VS2005 command prompt)e.g.xsd my.
xsd.exe (for example, at a VS2005 command prompt)

e.g.

xsd my.xsd /classes /enableDataBinding
xsd my.xsd /dataset
xsd /?

Marc

Hi SevDer,As Cor has suggested, you can use Visual Studio's built-in DataSet
Hi SevDer,

As Cor has suggested, you can use Visual Studio's built-in DataSet
generation feature to generate a typedDataset from a given xsd file.
However, in VS 2005, the supported approach is different from VS 2003(no
"generate dataset" command is available). Here is how to generate the
dataset from an xsd file in 2005:

1. Select the xsd file in the solution explorer
2. At the Property Grid (F4) find the CustomTool property and type
MSDataSetGenerator
The typed dataset will be generated for you.
<<<<<<<<<

Also, you can use the .net framework sdk's built-in xsd.exe utility to
generate custom classes from a given xsd file in commandline. This tool
support generating both normal classes and DataSet classes:

http://msdn2.microsoft.com/en-us/library/x6c1kb0s(VS.71).aspx

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.

Hi Steven,I've tried that earlier but it fails to work.
Hi Steven,

I've tried that earlier but it fails to work.
I'm getting the following message: "The custom tool 'MSDataSetGenerator'
failed. Unable to convert input xml file content to a dataset. Undefined
type: 'token'.

Also xsd.exe failed too.

By the way, designer view of the xsd actually shows without any problem.

And here is the XSD I have:


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.tagetsite.com/xmlns"
targetNamespace="http://www.targetSiteNamespace.com"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="CommonTypes.xsd" />
<xs:element name="MethodRQ">
<xs:annotation>
<xs:documentation>Documentation text</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:complexContent>
<xs:extension base="CoreRequest">
<xs:sequence>
<xs:element name="PurchaseReference" type="Reference">
<xs:annotation>
<xs:documentation>Documentation text</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="type" use="required">
<xs:annotation>
<xs:documentation>Documentation text</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="1" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>

CommonTypes.xsd is really a long one.
--

Sevket Seyalioglu
CTO
www.kbstours.com

Hi Marc,I tried the following but it did not work and failed.
Hi Marc,

I tried the following but it did not work and failed. I hope you know how to
overcome this.

What I tried:
------------------------------------------------------------
C:\xml>xsd MethodRQ.xsd /c /language:CS

Error message:
------------------------------------------------------------
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to50' is not declared. Line 337, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength1to2000' is not declared. Line 357, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:CommentType' is not declared, or is not a simple type. Line 358, position
6.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to50' is not declared. Line 578, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to255' is not declared. Line 749, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:targetsiteCustomerType' is not declared, or is not a simple type. Line
840, po
sition 4.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YYYYMMDDDate' is not declared, or is not a simple type. Line 858,
position 4.

Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:HHMMTime' is not declared, or is not a simple type. Line 863, position 4.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:SimpleGroup' is not declared, or is not a simple type. Line 891, position
4.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YYYYMMDDDate' is not declared, or is not a simple type. Line 973,
position 4.

Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YYYYMMDDDate' is not declared, or is not a simple type. Line 978,
position 4.

Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YYYYMMDDDate' is not declared, or is not a simple type. Line 1133,
position 4
..
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to50' is not declared. Line 1239, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to50' is not declared. Line 1452, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YesNo' is not declared, or is not a simple type. Line 1523, position 4.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength1to50' is not declared. Line 1534, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength1to4000' is not declared. Line 1562, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:EmailType' is not declared. Line 1612, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:Number1To99999' is not declared. Line 1750, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:Number1To999999999' is not declared. Line 1772, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YesNo' is not declared, or is not a simple type. Line 1849, position 6.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YesNo' is not declared, or is not a simple type. Line 1877, position 6.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to50' is not declared. Line 1958, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:SimpleGroup' is not declared, or is not a simple type. Line 1959,
position 6.

Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to2000' is not declared. Line 2027, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:SimpleGroup' is not declared, or is not a simple type. Line 2028,
position 6.

Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to1024' is not declared. Line 2332, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to1024' is not declared. Line 2352, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to255' is not declared. Line 2366, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength1to255' is not declared. Line 2394, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:preferLevelType' is not declared, or is not a simple type. Line 2740,
positio
n 4.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:preferLevelType' is not declared, or is not a simple type. Line 2804,
positio
n 4.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YesNo' is not declared, or is not a simple type. Line 2927, position 4.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:targetsiteServiceStatus' is not declared, or is not a simple type. Line
2932,
position 4.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to255' is not declared. Line 2976, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:SimpleGroup' is not declared, or is not a simple type. Line 2977,
position 6.

Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength1to1024' is not declared. Line 3053, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to255' is not declared. Line 3154, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:targetsiteInsuranceCoverageType' is not declared, or is not a simple
type. Lin
e 3155, position 6.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to50' is not declared. Line 3373, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to50' is not declared. Line 3389, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:targetsiteTransferType' is not declared, or is not a simple type. Line
3433, p
osition 6.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:targetsiteTransferType' is not declared, or is not a simple type. Line
3467, p
osition 4.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:StringLength0to255' is not declared. Line 3506, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:SimpleGroup' is not declared, or is not a simple type. Line 3507,
position 6.

Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:targetsiteZoneServiceType' is not declared, or is not a simple type. Line
3523
, position 6.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:targetsiteServiceStatus' is not declared. Line 2578, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:targetsitePurchaseStatus' is not declared. Line 2435, position 5.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:targetsiteFacilityAccessType' is not declared. Line 1726, position 7.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:VehicleTransmissionSimpleType' is not declared. Line 1391, position 7.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YesNo' is not declared. Line 1396, position 7.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YesNo' is not declared. Line 1417, position 7.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YesNo' is not declared. Line 1422, position 7.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:YesNo' is not declared. Line 1427, position 7.
Schema validation warning: Type 'http://www.targetsite.com/schema/messag
es:targetsiteServiceStatus' is not declared. Line 295, position 5.

Warning: Schema could not be validated. Class generation may fail or may
produce
incorrect results.

Error: Error generating classes for schema 'PurchaseCancelRQ'.
- The datatype 'http://www.targetsite.com/schema/messages:EmailType' i
s missing.

If you would like more help, please type "xsd /?".

The XSD I have:
------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.tagetsite.com/xmlns"
targetNamespace="http://www.targetSiteNamespace.com"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="CommonTypes.xsd" />
<xs:element name="MethodRQ">
<xs:annotation>
<xs:documentation>Documentation text</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:complexContent>
<xs:extension base="CoreRequest">
<xs:sequence>
<xs:element name="PurchaseReference" type="Reference">
<xs:annotation>
<xs:documentation>Documentation text</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="type" use="required">
<xs:annotation>
<xs:documentation>Documentation text</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="1" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>

--

Sevket Seyalioglu
CTO
www.kbstours.com

It looks like some of the entities aren't being resolved.
It looks like some of the entities are not being resolved. You could
try merging the include file (by hand) to see if that fixes it?

Marc

RE: XSD Class Generation
check XSDObjectGen.msi for .net 1.0 also have a look at :
http://devauthority.com/blogs/ram_marappan/archive/2006/10/03/4755.aspx

--
Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/


:

You, Sir, are a genius.
You, Sir, are a genius. I have spent soooo long trying to "fix" the
problem where the designer.cs files weren't being updated when I
edited my datasets. This got to the point where I ended up migrating
new and changed dataadapters to a whole new project. I've just tested
the MSDataSetGenerator option above, and it works!!! I looked at the
newer projects, and found they have this property set by default,
whereas the old ones did not - hence why they weren't regenerating.

I seriously owe you one - i figured this was a bug or something with
VS, and I've been ignored in the newsgroups when asking about it.
Many, many thanks.

Ship.


On Aug 23, 6:12 am, (e-mail address removed) (Steven Cheng[MSFT])
wrote:

Hello Yaron,This is also a great tool.However I still have the same problem.
Hello Yaron,

This is also a great tool.
However I still have the same problem.
The problem I am experiencing is, my xsd files are including other xsd files
and as a result when converting, they are unable to find certain types which
are included in the include xsd files.
I think those tools do not work with included xsds

--

Sevket Seyalioglu
CTO
www.kbstours.com

i already worked with xsd with reference (using the XSDObjectGen app), so it
i already worked with xsd with reference (using the XSDObjectGen app), so it
seems very strange.
--
Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/


:

I managed to work with it by combining included xsd.
I managed to work with it by combining included xsd.

Actually the included XSD also includes another one and I think thats where
I fail.

--

Sevket Seyalioglu
CTO
www.kbstours.com

Although I managed to make it working, it again failed when I tried to use the
Although I managed to make it working, it again failed when I tried to use
the object.
It failed to convert it into XML and gave me the following error:
There was an error generating the XML document.

(After merging included xsd's into one, in the class representation I've
split them into proper files while all of them are in the same namespace)

I will try the other tools where the first one is xsd.exe (I hope it will
help me out)
I will post my results.

--

Sevket Seyalioglu
CTO
www.kbstours.com

Well I tried xsd tool also but resulted the same..
Well I tried xsd tool also but resulted the same..

Please someone help me to use these xds files to make my life easy.
Otherwise I will have to deal with XML building :(

--

Sevket Seyalioglu
CTO
www.kbstours.com

Thanks for your reply and the XSD fragment,I'll perform some local test to see
Thanks for your reply and the XSD fragment,

I'll perform some local test to see whether I can get some result. I'll
update you soon.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.

Hi SevDer,Seems I can not get the XSD to work with out the refernced schema.
Hi SevDer,

Seems I can not get the XSD to work with out the refernced schema. How
large is it? Is it possible that you post it over internet so that I can
downloat it? Or you can send it to me through the following email(you can
package all the stuff in a zip pack):

string email = "stcheng" + "@" + "microsoft.com";

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.




--------------------

Hi SevDer,I have got your email and will have a look into the stuff.
Hi SevDer,

I have got your email and will have a look into the stuff. I'll update you
if I get any new finding on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.




--------------------

rights.

Thanks Steven,I will look forward for your response.-- CTOwww.kbstours.
Thanks Steven,

I will look forward for your response.

--


CTO
www.kbstours.com

Hi SevDer,I have performed some research on the three schemas you provided and
Hi SevDer,

I have performed some research on the three schemas you provided and did
found some syntax issues of them. The first problem I found is the base
type schemas doesn't have proper targetNamespace and default namespace
declared. I've included detailed info in the email sent to you. So far I
can get it to generate standard .net classes , but still encounter a error
when try generating dataset classes.

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead

--------------------
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<#[email protected]>
you

XSD Class Generation
Sevket,

Were you able to resolve the issue? I am facing the same problem. If you have already resolved it please let me know how you did it?

Thanks
Mani

XSD Class Generation tool
Defining a default namespace and target namespace explicitly in each of the included schema definition files resolved the "datatype ... missing" issue. Moreover, if there is a "primary" xsd that includes a set of subset xsds, then referencing both the primary xsd and the subset xsds in the XSD Class Generation command line causes the Schema validation warning, "already been declared". Only the primary xsd should be referenced in the command line.

I encountered these problems using .NET 2.0 XSD Class Generation tool. Does anyone know if this is still an issue using .NET 3.0?


Submitted via EggHeadCafe - Software Developer Portal of Choice
Using VSTO Add-In To Automate Frequent Excel 2007 Tasks
http://www.eggheadcafe.com/tutorial...60-39a86ccab5d6/using-vsto-addin-to-auto.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top