我有一个 .xsd 文件,用于使用 Visual Studio 的 xsd.exe 工具生成代码。
一些类成员是 Guids 并且 xsd.exe 工具给出了 2 个警告:
命名空间 ' http://microsoft.com/wsdl/types/ ' 无法在此架构中引用。
输入' http://microsoft.com/wsdl/types/:guid ' 未声明。
Guid 类型被识别,因为生成的 C# 文件有效且有效。
任何人都知道如何摆脱这些警告?
要验证的 XSD 和生成为 System.Guid 的类成员的正确语法是什么?
最佳答案
谢谢你们,
我找到了如何删除警告。
如 sysrqb说,wsdl 命名空间要么已被删除,要么从未存在。 xsd.exe 工具似乎在内部知道 Guid 定义,但它无法验证 xsd 架构。
如 boj指出,使用 Guid 验证模式的唯一方法是(重新)在模式中定义该类型。这里的技巧是将 Guid 类型添加到相同的“http://microsoft.com/wsdl/types”命名空间。这样,xsd.exe 就会在 http://microsoft.com/wsdl/types:Guid 之间做正确的关联。和 System.Guid
我为 guid 类型创建了一个新的 xsd 文件:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://microsoft.com/wsdl/types/" >
<xs:simpleType name="guid">
<xs:annotation>
<xs:documentation xml:lang="en">
The representation of a GUID, generally the id of an element.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="\{[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
然后,我使用原始 xsd 文件和这个新的 xsd 文件运行 xsd.exe:
xsd.exe myschema.xsd guid.xsd /c
关于xsd - 在 XSD 文件中使用 Guid 类型的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/687884/