xml XPath、XQuery 和 XPointer 之间的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/924551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:32:35  来源:igfitidea点击:

Difference between XPath, XQuery and XPointer

xmlxpathxquery

提问by Shashi

What is the difference between XPath, XQueryand XPointer? As far as I know, XQueryis an extended version of XPath. I have some basic knowledge of XPath. Is there any feature available in XPathwhich is not in XQuery? Yesterday, I heard a new word, XPointer. I am confused. Which language is used for which purpose?

之间有什么区别XPathXQueryXPointer?据我所知,XQueryXPath. 我有一些基本的知识XPath。是否有任何可用的功能XPath不在XQuery?昨天,我听到了一个新词,XPointer。我很迷惑。哪种语言用于哪种目的?

采纳答案by Matthew Flaschen

Wikipedia is a good place to start for questions like this. Generally, XPathis a language used to succinctly pinpoint exact XML nodes in a DOM. XQueryis a superset of XPath that also provides FLWORsyntax, which is SQL-like. Finally, XPointerincludes XPath, but also provides a simpler position-based addressing scheme.

维基百科是解决此类问题的好地方。通常,XPath是一种用于在 DOM 中简洁地查明精确的 XML 节点的语言。 XQuery是 XPath 的超集,它还提供FLWOR语法,类似于 SQL。最后,XPointer包括 XPath,但也提供了更简单的基于位置的寻址方案。

Of course, you can always read the W3C specs for full details.

当然,您可以随时阅读 W3C 规范以获取完整详细信息。

回答by grtjn

Though the answer by Matthew gives a good first impression, there is a lot more to tell about the mentioned standards, and there are many more that are related. There is a nice article from the XML Holland user group magazine made available online, that tells a lot about the history of XQuery, and takes various of these standards into perspective. The first part is quite relevant here:

尽管 Matthew 的回答给人留下了良好的第一印象,但关于上述标准还有很多要讲的内容,并且还有更多相关内容。XML Holland 用户组杂志在线提供了一篇不错的文章,它讲述了很多关于 XQuery 的历史,并从各个角度考虑了这些标准。第一部分在这里非常相关:

XQuerystands for XML Query Language. That already tells the essence. It is a language to select subsets and substructures from a large set of XML files. The result can be manipulated into something that is suitable to be used in, for example, a subsequent process, or to show in a web browser. XPathis used a lot in XQuery.

All XML standards have their own scope. I'll name a few. XSLTis a language for transforming XML into some other format. XPointeris an extension of XPath to address nodes more accurately within XML fragments or even subparts of nodes. XLinkis a standard to define relationships. XIncludeis a standard to compose multiple pieces of XML into one using for instance XLink relationships. And XProcis a standard with which can be described how XML documents should be processed to get to a desired end result. It is expressed itself in XML, and describes the process step by step, also called XML Pipelines. Within XProc you use a.o. XQuery, XSLT, and XInclude languages (and thus indirectly XPath, XPointer and XLink as well) to express what needs to be done exactly within each step.

All these standards are tied together. They are related, and depend on each other. The overlap between some of the mentioned XML standards is summarized quite well in the next image that you can also find at W3Schools:

XQuery代表XML 查询语言。这已经说明了本质。它是一种从大量 XML 文件中选择子集和子结构的语言。可以将结果处理为适合在例如后续过程中使用或在 Web 浏览器中显示的内容。XPath在 XQuery 中被大量使用。

所有 XML 标准都有自己的范围。我会列举几个。XSLT是一种将 XML 转换为其他格式的语言。XPointer是 XPath 的扩展,用于在 XML 片段甚至节点的子部分中更准确地寻址节点。XLink是定义关系的标准。XInclude是使用 XLink 关系等将多个 XML 组合成一个的标准。和XProc是一种标准,可用来描述应如何处理 XML 文档以获得所需的最终结果。它用 XML 表示,并逐步描述过程,也称为 XML 管道。在 XProc 中,您可以使用 Ao XQuery、XSLT 和 XInclude 语言(因此也间接使用 XPath、XPointer 和 XLink)来准确表达每个步骤中需要完成的工作。

所有这些标准都联系在一起。它们相互关联,相互依赖。下一张图片很好地总结了一些提到的 XML 标准之间的重叠,您也可以在W3Schools 上找到该图片:

What is XPath

什么是 XPath

Full article can be found here: http://grtjn.blogspot.nl/2011/10/xquery-novelties-revisited.html

全文可以在这里找到:http: //grtjn.blogspot.nl/2011/10/xquery-novelties-revisited.html

HTH!

哼!

回答by Rafal Rusin

Well, I think XQuery is something worth to be distinguished. XPath and XPointer are almost the same and are used for XML nodes selection. XQuery on the other hand is quite a big extension of XPath. For example it gives possibility of declaring custom functions. So it's more something like programming language, which works natively with XML. You can check out some samples here: embedding-xquery-in-java

嗯,我认为 XQuery 是值得区分的东西。XPath 和 XPointer 几乎相同,用于 XML 节点选择。另一方面,XQuery 是 XPath 的一个相当大的扩展。例如,它提供了声明自定义函数的可能性。所以它更像是编程语言,它本身就与 XML 一起工作。您可以在此处查看一些示例:embedding-xquery-in-java

Regards

问候

回答by Alain Couthures

XPath is intentionally limited to reading existing nodes.

XPath 有意限制为读取现有节点。

As XSLT, XQuery can create nodes. It can also update nodes (with XQuery Update Facility).

作为 XSLT,XQuery 可以创建节点。它还可以更新节点(使用 XQuery 更新工具)。

From my XQuery implementor point of view ;-)

从我的 XQuery 实现者的角度来看 ;-)