“缺少元素……"尝试使用 <element ref =/> 生成类 [英] "The element is missing.." trying to generate class with <element ref = />
问题描述
使用 VS 2013 附带的 XSD 工具,我收到以下消息,尝试从包含
- 的 xsd 生成类><块引用>
架构验证警告:'http://www.w3.org/2000/09/xmldsig#:KeyName' 元素未声明.第 14 行,位置 8.
警告:无法验证架构.类生成可能会失败或产生错误的结果.
错误:为架构测试"生成类时出错.- 元素 'http://www.w3.org/2000/09/xmldsig#:签名'丢失.
这是一个演示问题的缩减版 xsd:
我很确定导入和命名空间没问题.Resharper 和 VS Schema Designer 不会抱怨.我怀疑这是该工具不做的事情.
有什么想法可以继续吗?
原来这里已经回答了这个问题.
https://stackoverflow.com/a/17278163/2516770
我需要将导入的文件添加到xsd命令行参数的文件列表中:
xsd test.xsd xmldsig-core-schema.xsd/c
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?
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
这篇关于“缺少元素……"尝试使用 <element ref =/> 生成类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!