xml - 了解 XPath/XML 中的 NCName 和 QName

标签 xml xpath xml-namespaces w3c ebnf

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.

但是我很难理解那是什么,并且当单击链接时,它似乎给出了“语法/语法”定义,但实际上并不是一个对我来说“有意义”的定义(即,可以向我解释)而不仅仅是“哦,它向解析器代表了这些字符”)。这些的定义是什么以及每个的示例是什么?

最佳答案

需要NCNameQName出现支持XML Namespaces .

NCName

Non-CNAME 可以包含 XML 中允许的任何字符 Name 冒号除外: :

NCName         ::= Name - (Char* ':' Char*)

示例: pNCName ,其中<p>可能是段落开始标记。

定义不能包含 : 的名称的动机是预约:作为 XML namespace 前缀和名称的其余部分(称为本地部分)之间的分隔符。这让我们想到了 QName...

QName

Q合格的NAME可能(但不一定)具有与本地部分通过 : 分隔的命名空间前缀。 :

QName          ::= PrefixedName | UnprefixedName
PrefixedName   ::= Prefix ':' LocalPart
UnprefixedName ::= LocalPart
Prefix         ::= NCName
LocalPart      ::= NCName

示例: w:pQName ,和<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/

相关文章:

c# - 从 XML 填充类对象

xpath - 如何从 XML 获取 XPath?

linux - xquery 无法加载 http ://expath. org/ns/http-client

java - 如何使用 Java 将子元素附加到大型 XML 文件?

java - Android 整数 xml 值到字符串

javascript - 如何在 HTML 中实现 XSLT 文件

haskell - 在HXT中进行逻辑或运算而不重复结果

java - XPath:如何从一个 XHTML 节点收集多个文本片段?

html - XMLNS 和搜索引擎的语义理解

xml - 是否(实际上)有一个 1 :1 correspondence between an XML schema and an XML namespace?