ChatGPT解决这个技术问题 Extra ChatGPT

Difference between XPath, XQuery and XPointer

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


J
Joe Wicentowski

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

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


C
Community

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:

XQuery stands 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. XPath is used a lot in XQuery. All XML standards have their own scope. I’ll name a few. XSLT is a language for transforming XML into some other format. XPointer is an extension of XPath to address nodes more accurately within XML fragments or even subparts of nodes. XLink is a standard to define relationships. XInclude is a standard to compose multiple pieces of XML into one using for instance XLink relationships. And XProc is 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:

https://i.stack.imgur.com/EQ8y6.gif

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

HTH!


In addition to the above, Querying XML was just the start for XQuery. Since its inception additional standards have been defined, like XQuery Full-Text, and XQuery Update Facility, to make it even more versatile than it already is on its own. Though a little dated by now, the above referenced article goes through most of these..
R
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

Regards


A
Alain Couthures

XPath is intentionally limited to reading existing nodes.

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

From my XQuery implementor point of view ;-)


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now