在 XSD 文件中使用 Guid 类型的正确方法是什么? [英] What is the correct way of using the Guid type in a XSD file?

查看:20
本文介绍了在 XSD 文件中使用 Guid 类型的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .xsd 文件,用于使用 Visual Studio 中的 xsd.exe 工具生成代码.一些类成员是 Guid,xsd.exe 工具给出 2 个警告:

I have a .xsd file which I use to generate code with the xsd.exe tool from Visual Studio. Some class members are Guids and the xsd.exe tool gives 2 warnings:

命名空间 'http://microsoft.com/wsdl/types/' 不适用于在此架构中被引用.类型 'http://microsoft.com/wsdl/types/:guid' 未声明.

Namespace 'http://microsoft.com/wsdl/types/' is not available to be referenced in this schema. Type 'http://microsoft.com/wsdl/types/:guid' is not declared.

Guid 类型被识别,因为生成的 C# 文件有效且有效.任何人都知道如何摆脱这些警告?

The Guid type is recognized because the generated C# file is valid and works. Anyone knows how to get rid of those warnings?

要验证 XSD 并将类成员生成为 System.Guid 的正确语法是什么?

What is the correct syntax for the XSD to be validated AND class members being generated as System.Guid?

推荐答案

谢谢大家,我找到了如何删除警告.

Thank you all, I found how to remove the warnings.

正如 sysrqb 所说,wsdl 命名空间要么已被删除,要么从未存在.xsd.exe 工具似乎在内部知道 Guid 定义,但它无法验证 xsd 架构.

As sysrqb said, the wsdl namespace has either been deleted or never existed. It seems that the xsd.exe tool knows the Guid definition internally, but it cannot validate the xsd schema.

正如 boj 指出的那样,验证带有 Guid 的架构的唯一方法是(重新)定义模式中的那种类型.这里的技巧是将 Guid 类型添加到相同的http://microsoft.com/wsdl/types"命名空间.这样,xsd.exe 将在 http://microsoft.com/wsdl/types:Guid 和 System.Guid

As boj pointed out, the only way to validate the schema with Guids in it, is to (re)define that type in a schema. The trick here is to add the Guid type to the same "http://microsoft.com/wsdl/types" namespace. This way, the xsd.exe will do the proper association between http://microsoft.com/wsdl/types:Guid and System.Guid

我为 guid 类型创建了一个新的 xsd 文件:

I made a new xsd file for the guid type:

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

Then, I run xsd.exe with both my original xsd file and this new xsd file:

xsd.exe myschema.xsd guid.xsd /c

这篇关于在 XSD 文件中使用 Guid 类型的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆