XML 命名空间和无前缀属性 [英] XML Namespaces and Unprefixed Attributes

查看:36
本文介绍了XML 命名空间和无前缀属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XML Namespaces 的规范解释说,无前缀属性的解释是由元素决定的它们出现在上面.而且无前缀属性名称的命名空间名称始终没有值.

The specification of XML Namespaces explains that the interpretation of unprefixed attributes is determined by the element on which they appear. And that the namespace name for an unprefixed attribute name always has no value.

在以下情况下,此规则如何应用于属性jid的命名空间.

How does this rule apply to the namespace of the attribute jid in the following cases.

<query xmlns="jabber:iq:roster">
  <item jid="romeo@example.com"></item>
</query>

如果命名空间的声明和相关属性都没有前缀,则属性jid 位于命名空间jabber:iq:roster 中.

If the declaration of the namespace and the attribute in question both don't have an prefix, the attribute jid is in the namespace jabber:iq:roster.

<q:query xmlns:q="jabber:iq:roster">
  <q:item q:jid="romeo@example.com"></q:item>
</q:query>

如果命名空间的声明和属性的前缀相同,则属性jid也有命名空间jabber:iq:roster:

If both, the declaration of the namespace and the attribute have the same prefix, the attribute jidalso has the namespace jabber:iq:roster:

<q:query xmlns:q="jabber:iq:roster">
  <q:item jid="romeo@example.com"></q:item>
</q:query>

但是如果命名空间是用前缀声明的,但属性没有前缀,那么属性在哪个命名空间中?我会假设,属性 jid

But in which namespace is the attribute if the namespace is declared with an prefix but the attribute doesn't have a prefix? I would assume, that the attribute jid

  1. 在父元素中声明了默认命名空间,

  1. has the default namespace declared in a parent element,

<parent xmlns="http://example.com">
  <q:query xmlns:q="jabber:iq:roster">
    <q:item jid="romeo@example.com"></q:item>
  </q:query>
</parent>

  • 或者没有命名空间,如果没有这样的声明.
  • 我做对了吗?

    推荐答案

    没有前缀的属性总是在空的命名空间中,即它没有命名空间.封闭元素是否具有名称空间并不重要.这是我对您提到的第二个语句的阅读,这是对我使用过的所有 XML 工具的解释.

    An attribute without prefix is always in the empty name space, i.e. it has no name space. It is doesn't matter whether the enclosing element has a name space or not. That's my reading of the second statement you refer to, and that is the interpretation of all the XML tools I've used.

    这篇关于XML 命名空间和无前缀属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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