5

Using the XSD tool included with VS 2013, I receive the following message trying to generate a class from an xsd that contains <xsd:element ref=.../> -

Schema validation warning: The 'http://www.w3.org/2000/09/xmldsig#:KeyName' element is not declared. Line 14, position 8.

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

Error: Error generating classes for schema 'test'. - The element 'http://www.w3.org/2000/09/xmldsig#:Signature' is missing.

This is a cut down xsd that demonstrates the problem:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema id="test"
    targetNamespace="http://tempuri.org/test.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/test.xsd"
    xmlns:mstns="http://tempuri.org/test.xsd"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:sig="http://www.w3.org/2000/09/xmldsig#"
>
  <xsd:import schemaLocation="xmldsig-core-schema.xsd" namespace="http://www.w3.org/2000/09/xmldsig#" />

  <xsd:complexType name="test" >
    <xsd:sequence >
      <xsd:element ref="sig:Signature" minOccurs="0" maxOccurs="unbounded"></xsd:element>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:element type="test" name="top"/>
</xsd:schema>

I'm pretty sure the import and namespaces are okay. Resharper and the VS Schema Designer do not complain. I suspect that this is something that the tool just doesn't do.

Any ideas how I can proceed?

Keith Payne
  • 3,002
  • 16
  • 30
  • The error message you're getting is pretty good evidence that the import is *not* okay; if it were okay, the element would not be undefined. Your `xsd:import` element is fine, but the DSig schema is almost certainly not being successfully imported; a common cause is failure to find the schema document. – C. M. Sperberg-McQueen Mar 07 '15 at 01:49

1 Answers1

19

It turns out that this has been answered here.

https://stackoverflow.com/a/17278163/2516770

I need to add the imported file to the file list of the xsd command line parameters:

xsd test.xsd xmldsig-core-schema.xsd /c

Community
  • 1
  • 1
Keith Payne
  • 3,002
  • 16
  • 30