命名空间之后的 uri 实际用于什么?

发布于 2024-10-05 12:58:50 字数 963 浏览 0 评论 0原文

第 5、6、7 行中的 URI 实际上必须指向任何内容吗?

当我将它们指向 duff url 时,它似乎仍然可以验证我的 xml,那么有什么意义呢?

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="UploadXSD"
    targetNamespace="UploadXSD"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/UploadXSD.xsd"
    xmlns:mstns="http://tempuri.org/UploadXSD.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="Video">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Title" minOccurs="1" type="xs:string"></xs:element>
        <xs:element name="Description" minOccurs="1" type="xs:string"></xs:element>
        <xs:element name="Contributor" minOccurs="1" type="xs:string"></xs:element>
        <xs:element name="Subject" minOccurs="1" type="xs:string"></xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

Do the URI's in lines ( 5,6,7 ) actually have to point to anything?

When I point them at duff urls it still seems to work to validate my xml, so what is the point?

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="UploadXSD"
    targetNamespace="UploadXSD"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/UploadXSD.xsd"
    xmlns:mstns="http://tempuri.org/UploadXSD.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="Video">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Title" minOccurs="1" type="xs:string"></xs:element>
        <xs:element name="Description" minOccurs="1" type="xs:string"></xs:element>
        <xs:element name="Contributor" minOccurs="1" type="xs:string"></xs:element>
        <xs:element name="Subject" minOccurs="1" type="xs:string"></xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

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

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

发布评论

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

评论(2

请持续率性 2024-10-12 12:58:51

使用 URN 作为命名空间的要点是它们是唯一的。例如,您还可以使用 GUID,但这样它们更具可读性。

当然,使用 URN 可以让您可能将它们指向实际资源,例如 xsd 文件,但这是额外的好处,但不是必需的。

“tempuri”只是默认名称(“temp”+“uri”),您应该将其替换为真实的 URN 以避免命名空间冲突。

XMLSchema 命名空间实际上指向一个包含有关 XML-Schema 信息的网站。

如果您经常使用 XML 文档和架构,请至少阅读入门,以获取关于 XML 模式的可能性的想法。有关 XML 命名空间的更多信息位于此处

The point of using URNs as namespace is that they are unique. You could also use a GUID for example, but this way they are more readable.

Of course, using URNs gives you the possibility to point them to an actual resource, like a xsd file, but that's an added bonus and not necessary.

The "tempuri" things are just default names ("temp"+"uri"), which you should replace with a real URN to avoid namespace collisiions.

The XMLSchema namespace actually points to a website that contains information about XML-Schema.

If you use XML-Documents and Schemas regurlarly, read at least the primer, to get an idea about the possibilities of XML-Schema. More info about XML Namespaces is here.

南街九尾狐 2024-10-12 12:58:51

XML 命名空间 URI(不是 URL)只是不透明的字符串。它们旨在防止 XML 结构中的冲突。就像任何支持命名空间的其他语言一样,它们不指向任何东西,但定义了一个唯一的名称,通过该名称可以使用其内容。

由于使用 DNS 注册很容易,并且可以保证全局唯一,因此在您发布的架构中使用这些名称是一种常见的做法。然而,它不是必需的,GUID 也可以工作(尽管它需要一个方案前缀来符合 URI 规范)。

回答你的问题:

不,URI 不需要指向任何东西(它们是 ID)。

当您更改命名空间的 URI 时,您只是更改了命名空间名称,仅此而已。

希望这有帮助,

XML Namespace URI's (not URL's) are just opaque strings. They are intended to prevent collisions in XML structures. Just like any namespace capable other language, they don't point to anything but they define a unique name through which its content can be used.

Since it's easy to use a DNS registration and be guarenteed to be globally unique, it is a common practice to use those name in the schema's you publish. It is however not needed and a GUID would work (although it needs a scheme prefix to comply to the URI spec).

To answer your questions:

No, URI's do not need to point anything (they are IDs).

When you change a URI of a namespace, you change the namespace name, nothing else.

Hope this helps,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文