如何将 GUID simpleType 添加到 XML 模式中?

发布于 2024-07-25 22:17:56 字数 101 浏览 2 评论 0原文

我正在尝试创建一个 XML 架构,该架构允许将属性值存储为本机格式的 GUID。 我可以将其设置为字符串,但最好将其存储为真正的 GUID。

有什么想法如何去做吗?

I'm trying to create an XML schema, which enables an attribute value to be stored as an GUID in native format. I could set it up as a string, but it would be nice to store it as a real GUID.

Any ideas how to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清晨说晚安 2024-08-01 22:17:56

您可以通过使用正则表达式限制字符串来定义自己的自定义简单类型“GUID”,如下所示:

<xs:simpleType name="GUID">
  <xs:restriction base="xs:string">
    <xs:pattern value="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})|(\{[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\})"/>
  </xs:restriction>
</xs:simpleType>

You can define your own custom simple type "GUID" by restricting a string using a regular expression like this:

<xs:simpleType name="GUID">
  <xs:restriction base="xs:string">
    <xs:pattern value="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})|(\{[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\})"/>
  </xs:restriction>
</xs:simpleType>
只为守护你 2024-08-01 22:17:56

XML 基本上只包含字符串,尽管 XSD 还定义了某些其他基本类型。 然而,GUID 并不在其中。

您可以为 GUID 类型定义自己的架构。 很多人都这样做过。 Microsoft OneNote 团队的做法如下: http://msdn .microsoft.com/en-us/library/aa203890(office.11​​).aspx

XML basically contains only strings, although XSD also defines certain other primitive types. GUID, however, is not among them.

You can define your own schema for a GUID type. Lots of people have done this. Here's how the Microsoft OneNote team did it: http://msdn.microsoft.com/en-us/library/aa203890(office.11).aspx.

廻憶裏菂餘溫 2024-08-01 22:17:56

我已经弄清楚了。 有时阅读文档会有所帮助。 这就是它的工作方式。

    <xs:simpleType name="GUID">
      <xs:restriction base="xs:string">
        <xs:pattern value="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})|(\{[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\})"/>
      </xs:restriction>
    </xs:simpleType>


    <xs:element name="ruleident">
      <xs:complexType>
        <xs:attribute name="ruleGuid" >
          <xs:simpleType>
            <xs:restriction base ="GUID"/>
           </xs:simpleType>
        </xs:attribute >
      </xs:complexType >
    </xs:element>

I've sussed it out. Sometimes it helps to read the docs. This is how it will work.

    <xs:simpleType name="GUID">
      <xs:restriction base="xs:string">
        <xs:pattern value="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})|(\{[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\})"/>
      </xs:restriction>
    </xs:simpleType>


    <xs:element name="ruleident">
      <xs:complexType>
        <xs:attribute name="ruleGuid" >
          <xs:simpleType>
            <xs:restriction base ="GUID"/>
           </xs:simpleType>
        </xs:attribute >
      </xs:complexType >
    </xs:element>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文