“元素丢失..”尝试使用<element ref =“/”> </element>生成类

时间:2015-03-06 16:21:10

标签: c# xsd schema xsd.exe

使用VS 2013附带的XSD工具,我收到以下消息,试图从包含<xsd:element ref=.../>的xsd生成一个类 -

  

架构验证警告:未声明“http://www.w3.org/2000/09/xmldsig#:KeyName”元素。第14行,第8位。

     

警告:无法验证架构。类生成可能会失败或可能产生不正确的结果。

     

错误:为架构'test'生成类时出错。      - 缺少元素“http://www.w3.org/2000/09/xmldsig#:Signature”。

这是一个用于演示问题的缩减xsd:

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

我很确定导入和名称空间是可以的。 Resharper和VS Schema Designer不会抱怨。我怀疑这是该工具不能做的事情。

我有什么想法可以继续吗?

1 个答案:

答案 0 :(得分:12)

事实证明这已在这里得到解答。

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

我需要将导入的文件添加到xsd命令行参数的文件列表中:

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