什么是 XML 命名空间,它与 Spring Transactions 有什么关系?

发布于 2024-10-14 06:47:27 字数 146 浏览 5 评论 0原文

我刚刚浏览了一个 Spring 事务教程,其中提到有一些可用于声明式事务管理的元素,它们是在 tx 命名空间中定义的。 tx 命名空间实际上包含什么。它在哪里定义、注册等?为什么我需要命名空间?

我想了解有关命名空间的一般信息,而不仅仅是特定于 tx 命名空间。

I just went through a spring transaction tutorial which mentions that there are some elements available for declarative transaction management and they are defined in the tx namespace. What actually does the tx namespace contain. Where is it defined, registered etc? Why would i need a namespace?

I want to know in general about the namespaces not just specific to the tx namespace.

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

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

发布评论

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

评论(1

红焚 2024-10-21 06:47:27

XML 命名空间 只是一个标记,由于缺乏更好的描述,它标识了其“版本”特定的标签或属性是。这个想法是为了防止冲突,例如,如果您使用的是由多个人/程序/标准机构/等定义的元素的 XML。例如,我编写的使用 xml 的程序可能会使用命名空间 http://www.ttdi.us/xml/myapp。然后,我可以定义像 这样的标签,而不必担心在其他地方,有人也可能出于自己的目的而使用

<thing xmlns="http://www.ttdi.us/xml/myapp"
       xmlns:pie="http://somebodyelse.example/delicious/pie">
<!-- this defines that we have a "thing"
     in the namespace "http://www.ttdi.us/xml/myapp" -->
<!-- also it says that anything with the prefix pie:
     is from a different namespace. -->
    <name color="brown" pie:color="crispy">Bob</name>
    <!-- so this tag has the color "brown" for the attribute in my namespace
         but "crispy" in somebodyelse's pie namespace.
         We can use the same tag/attribute names without any trouble. -->
    <pie:flavor>Blueberry</pie:flavor>
</thing>

命名空间不需要是在任何地方“注册”;它可以是您想要的任何 URI。

简而言之,如果您正在创建自己的 XML 文档,并且您认为其他 XML 的一些内容可能会嵌入到您的文档中,反之亦然,则值得声明一个命名空间。

因此,spring tx 命名空间只是一种在 XML 配置文档中标识“属于”Spring Transactions 的事物的方法。访问 Spring TX 命名空间的 URL 会引导您进入 XML 模式(关于哪些元素、属性的规则) ,以及您可以拥有的值)用于各个版本的 Spring Transactions。有关可以使用哪些配置设置的更多信息,请参阅 Spring 文档

An XML namespace is just a token that, for lack of a better description, identifies whose "version" a particular tag or attribute is. The idea is to prevent conflicts if, for instance, you're using XML with elements defined by multiple people/programs/standards bodies/etc. For instance, a program that I write that uses xml might use the namespace http://www.ttdi.us/xml/myapp. Then, I can define tags like <name> without worrying that somewhere else, somebody might also be using <name> for their own purposes:

<thing xmlns="http://www.ttdi.us/xml/myapp"
       xmlns:pie="http://somebodyelse.example/delicious/pie">
<!-- this defines that we have a "thing"
     in the namespace "http://www.ttdi.us/xml/myapp" -->
<!-- also it says that anything with the prefix pie:
     is from a different namespace. -->
    <name color="brown" pie:color="crispy">Bob</name>
    <!-- so this tag has the color "brown" for the attribute in my namespace
         but "crispy" in somebodyelse's pie namespace.
         We can use the same tag/attribute names without any trouble. -->
    <pie:flavor>Blueberry</pie:flavor>
</thing>

A namespace need not be "registered" anywhere; it can just be any URI you want.

In short, if you're making your own XML documents and you think that it's likely that bits of other XML will be embedded in yours or vice-versa, it's worth declaring a namespace.

So, the spring tx namespace is merely a way of identifying things which "belong to" Spring Transactions in an XML configuration document. Visiting the URL of the Spring TX namespace leads you to XML Schemas (rules for what elements, attributes, and values you can have) for the various versions of Spring Transactions. More information about what configuration settings you can use are in Spring's documentation.

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