27

This is the command i'm running:

xsd.exe -c -l:c# D:\Documents\DEV\SARPilot\Docs\schemas\06-141r2\06-141r2.xsd

These are the errors i'm getting:

Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
Schema validation warning: Undefined complexType 'http://www.opengis.net/sps/0:ParameterDescriptorType' is used as a base for comp
lex type extension. Line 617, position 2.
Schema validation warning: Undefined complexType 'http://www.opengis.net/ows:GetCapabilitiesType' is used as a base for complex ty
pe extension. Line 23, position 2.
Schema validation warning: Undefined complexType 'http://www.opengis.net/ows:CapabilitiesBaseType' is used as a base for complex t
ype extension. Line 35, position 2.
Schema validation warning: The 'http://www.opengis.net/gml:Point' element is not declared. Line 869, position 2.
Schema validation warning: The 'http://www.opengis.net/gml:Polygon' element is not declared. Line 870, position 2.
Schema validation warning: The 'http://www.opengis.net/gml:Rectangle' element is not declared. Line 871, position 2.
Schema validation warning: The 'http://www.opengis.net/sps/0:Parameter' element is not declared. Line 381, position 2.
Schema validation warning: The 'http://www.opengis.net/sps/0:ID' element is not declared. Line 451, position 2.

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

Error: Error generating classes for schema 'D:\Documents\DEV\SARPilot\Docs\schemas\06-141r2\06-141r2'.
  - The datatype 'http://www.opengis.net/ows:GetCapabilitiesType' is missing.

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

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>

The XSD file was copy/pasted from Appendix A in the following document: http://services.eoportal.org/portal/documents/06-141r2_Ordering_Services_for_Earth_Observation_Products_0.9.2.pdf

capdragon
  • 14,565
  • 24
  • 107
  • 153

2 Answers2

39

The XML Schema included in the PDF document you linked has references to several other XSD files using the <import> element. You will need to download these additional schema files and make sure that the path references in the <import> elements are pointing to the correct locations on your local computer.

If you are still getting errors, it is because xsd.exe could not follow up on external references. To solve this issue, specify all the required XSD files directly on the command line as follows:

xsd.exe /c MySchema.xsd Import01.xsd Import02.xsd Include01.xsd Include02.xsd

where Import01.xsd, Import02.xsd, Include01.xsd and Include02.xsd are XSD files referenced via import and include elements in MySchema.xsd.

Asti
  • 12,447
  • 29
  • 38
pmartin
  • 2,731
  • 1
  • 25
  • 30
  • I added all files locally, including the files those file were calling. But still, same error. I'm pretty sure my problem is the error:The datatype 'http://www.opengis.net/ows:GetCapabilitiesType' is missing. – capdragon Dec 20 '10 at 19:07
  • Did you add all the schemas into the same folder? The `import` statements that I saw referenced these additional schemas at different directory levels. You might still have an issue where it's not finding the referenced schemas due to the pathing. – pmartin Dec 20 '10 at 19:38
  • 3
    You can add them to your command line and leave the "hintpaths" intact. Just mention each schema imported (and also if those import again, rinse & repeat). xsd.exe /c TopSchema.xsd ImportSchema1.xsd ... ImportOfImportSchema1.xsd – Marvin Smit Dec 20 '10 at 19:39
  • sorry, what do you mean by "hintpaths" and "rinse & repeat"? – capdragon Dec 21 '10 at 15:23
  • I tried using other tools such as svcutil and Xsd2Code but i get errors in each, could the schema files be messed up? – capdragon Dec 21 '10 at 15:25
  • like this? "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\xsd.exe" -c -l:c# 06-141r2.xsd ..\swe\sweCommon\1.0.1\swe.xsd ..\ows\2.0\owsGetCapabilities.xsd ..\sps\Order_spsCommon.xsd ..\gml\3.1.1\base\gml.xsd – capdragon Dec 21 '10 at 15:34
  • @capdragon You mentioned above that the Schema was copy/pasted from a PDF document. This is certainly a recipe for errors in the copy/paste process. Do you have any tools available (like XMLSpy) to validate your schema files? You might start by just making sure that the schema files are well-formed and valid. It could be that you missed a character during the copy/paste that is messing things up. – pmartin Dec 21 '10 at 16:53
  • I found the schema files i needed in a zip file. I ran XMLSpy and it validated fine, but i kept getting errors. So i tried another tool. LINQToXSD and it works with this tool. – capdragon Dec 21 '10 at 21:40
30

I had the same issue and this is how I solved it:

1) Copied all the xsd files referenced in xsd targeted for code generation to the same location i.e. "C:\Projects\Project1\Documents\xsds\strucutre". 2) Mentioned all the referred xsd files while executing xsd.exe:

C:\Projects\Project1\Documents\xsds\strucutre>"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\xsd" structure.xsd RefXsd1.xsd RefXsd2.xsd RefXsd3.xsd /c /o:C:\Projects\Project1\Documents\ClassStructure

A c-sharp file, containing the entities mentioned in xsds, was generated under folder C:\Projects\Project1\Documents\ClassStructure.

Hope this helps!

DiligentKarma
  • 5,198
  • 1
  • 30
  • 33
  • Thank you! I had been pulling my hair out over this for the last few hours. I had no idea that you had to list out all the xsd files that are being imported/included in the main xsd (as well as any imports/indludes those have). – Hobo Spider Dec 07 '13 at 00:23
  • 1
    I'm still having this warnings, even when I carefully listing all referred .xsd files. Not sure why – Sharif Feb 16 '17 at 16:51