XSD Class Generation

S

SevDer

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.
 
C

Cor Ligthert[MVP]

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
 
M

Marc Gravell

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

e.g.

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

Marc
 
S

Steven Cheng[MSFT]

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:

#XML Schema Definition Tool (Xsd.exe)
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.
 
S

SevDer

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.
 
S

SevDer

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>
 
M

Marc Gravell

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

Marc
 
B

Barney

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.
 
S

SevDer

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
 
G

Guest

i already worked with xsd with reference (using the XSDObjectGen app), so it
seems very strange.
 
S

SevDer

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.
 
S

SevDer

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.
 
S

SevDer

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 :(
 
S

Steven Cheng[MSFT]

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.
 
S

Steven Cheng[MSFT]

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.




--------------------
 
S

Steven Cheng[MSFT]

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.




--------------------
 
S

Steven Cheng[MSFT]

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

--------------------
From: "KBSTours" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
 
M

Mani Jayadevan

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


EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 

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