XML namespaces and attributes

前端 未结 4 663
梦谈多话
梦谈多话 2020-11-27 15:43

I\'m trying to understand how namespaces work in XML. When I have an element like foo:bar, the attributes will often not have namespaces on them. But sometimes they will. Ar

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 16:28

    Read up at 6.1 Namespace Scoping and 6.2 Namespace Defaulting on w3c.

    Basically:

    The scope of a namespace declaration declaring a prefix extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag

    However, the text here doesn't seem to explain if means a is foo:a or the default namespace in the context. I would assume that it does not refer to foo:a, but rather the documents default namespace a. Considering this quote at least:

    Such a namespace declaration applies to all element and attribute names within its scope whose prefix matches that specified in the declaration.

    Ie. the namespace "foo:" only applies to elements prefixed with foo:

提交回复
热议问题