NCName
的基本解释是什么?和 QName
在 XML 中? XPath page
上多次提到它。 ,例如:
The name function returns a string containing a QName representing the expanded-name of the node in the argument node-set that is first in document order. The QName must represent the expanded-name with respect to the namespace declarations in effect on the node whose expanded-name is being represented. Typically, this will be the QName that occurred in the XML source. This need not be the case if there are namespace declarations in effect on the node that associate multiple prefixes with the same namespace. However, an implementation may include information about the original prefix in its representation of nodes; in this case, an implementation can ensure that the returned string is always the same as the QName used in the XML source. If the argument node-set is empty or the first node has no expanded-name, an empty string is returned. If the argument it omitted, it defaults to a node-set with the context node as its only member.
但是我很难理解那是什么,并且当单击链接时,它似乎给出了“语法/语法”定义,但实际上并不是一个对我来说“有意义”的定义(即,可以向我解释)而不仅仅是“哦,它向解析器代表了这些字符”)。这些的定义是什么以及每个的示例是什么?
最佳答案
需要NCName
与 QName
出现支持XML Namespaces .
NCName
Non-CNAME 可以包含 XML 中允许的任何字符 Name
冒号除外,:
:
NCName ::= Name - (Char* ':' Char*)
示例: p
是 NCName
,其中<p>
可能是段落开始标记。
定义不能包含 :
的名称的动机是预约:
作为 XML namespace 前缀和名称的其余部分(称为本地部分)之间的分隔符。这让我们想到了 QName...
QName
Q合格的NAME可能(但不一定)具有与本地部分通过 :
分隔的命名空间前缀。 :
QName ::= PrefixedName | UnprefixedName
PrefixedName ::= Prefix ':' LocalPart
UnprefixedName ::= LocalPart
Prefix ::= NCName
LocalPart ::= NCName
示例: w:p
是 QName
,和<w:p>
是 OOXML 中的段落标记,其中 w
是声明为 xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
的命名空间前缀.
另请参阅
关于xml - 了解 XPath/XML 中的 NCName 和 QName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65085470/