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

查看:133
本文介绍了在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天全站免登陆