到同一文档中另一个节点的简单 XLink 的一般要点似乎是:
<root xmlns:xlink="http://www.w3.org/1999/xlink">
<firstChild id="ID1" />
...
<ref xlink:href="#ID1" />
</root>
在不使用 XPointer 或 XPath 的情况下,这是否与使用 XLink 所能做的一样多?你能做一个 XLink 吗,比方说,引用 customId
的东西,看起来像:
<root xmlns:xlink="http://www.w3.org/1999/xlink">
<firstChild id="ID1" customId="{1234-5678}" />
...
<ref xlink:href="#customId/{1234-5678}" />
</root>
请不要只让我引用 W3 spec - 我不了解你,但需要一种特殊的人才能解读它们,而我今天不是那种人!
无论如何,我知道大多数 XLink 似乎都是关于引用外部资源的,而且我见过的大多数示例都使用指向 Web 资源的 http 链接...我只是想知道您可以用 XLink 做什么引用 XML 文档中的特定部分。
谢谢!
最佳答案
我认为不使用 XPointer 或 XPath 是行不通的。我知道您不想被提及到规范,但是:
来自XLink spec :
the format of the fragment identifier [...] used within the URI reference is specified by the XPointer specification.
来自XPointer spec :
XPointer [...] is based on the XML Path Language (XPath)
所以我会说它是这样的:
<root xmlns:xlink="http://www.w3.org/1999/xlink">
<firstChild id="ID1" customId="{1234-5678}" />
...
<ref xlink:href="#xpointer(/root/firstChild[@customId = '{1234-5678}'])" />
</root>
关于xml - 使用 XLink 引用同一文档中的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/968394/