Solved

Why XQUERY is needed when XPATH is already there ?

Posted on 2007-11-22
6
397 Views
Last Modified: 2013-11-18
Hi,

Can you please explain me in simple terms why XQUERY is necessary when XPATH is already there ?

Thanks
0
Comment
Question by:kishore_peddi
  • 4
  • 2
6 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20336455
XPath is an addressing mechanism, that is used to address portions of an XML document
XQuery is a query language that uses XPath for addressing

XPath only serves the addressing part of the equation
If you want to create something out of a source XML, you need some sort of a programming language around XPath
(an example would be the DOM expression in JavaScript, as you did in your previous question)
There are two standardised languages that use XPath for addressing, but also allow to do something with the result
XQuery if the bulk of the work is searching and creating some sort of resultset
XSLT if the bulk of the work is transformation

XPath returns a nodeset. JavaScript DOM, XQuery or XSLT do something with this nodeset

I hope this clarifies things

If you want to do something with a browser, you need JavaScript DOM or XSLT
XQuery requires XPath2 and there is no support for that in browsers yet

cheers

Geert
0
 

Author Comment

by:kishore_peddi
ID: 20336485
I have the following info:

"XQuery is to XML what SQL is to database tables" - especially like FOR, LET, WHERE, ORDER BY, RETURN.

By using this XML can you provide FLWOR example ?

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
      <book category="COOKING">
            <title lang="en">Everyday Italian</title>
            <author>Giada De Laurentiis</author>
              <year>2005</year>
              <price>30.00</price>
      </book>
      <book category="CHILDREN">
              <title lang="en">Harry Potter</title>
              <author>J K. Rowling</author>
              <year>2005</year>
              <price>29.99</price>
      </book>
      <book category="WINDOWS">
              <title lang="en">Learning VB.NET and VC#.NET</title>
              <author>James Linn</author>
              <year>2003</year>
              <price>49.99</price>
      </book>
      <book category="WEB">
              <title lang="en">Learning HTML</title>
              <author>Erik T. Ray</author>
              <year>2003</year>
              <price>39.95</price>
      </book>
</bookstore>

Appreciate your time, effort and patience !!

Thanks

0
 

Author Comment

by:kishore_peddi
ID: 20337012
Here is the HTML file i have tried - for simple example. But it does not work for me IE:

<html>
      <body>
     
      <script type="text/vbscript">
     
      for $x in doc("Books.xml")/bookstore/book
      where $x/price>30
      order by $x/title
      return $x/title

      </script>
     
      </body>
</html>

Can you please let me know where i am missing ? Thanks
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:kishore_peddi
ID: 20337051
<html>
      <body>
     
      <script type="text/vbscript">
     
      for $x in doc("Books.xml")/bookstore/book
      where $x/price>30
      order by $x/title
      return $x/title

      'CAN YOU PLEASE PROVIDE ME CODE THAT OUTPUTS THE return VALUE TO BROWSER ?

      </script>
     
      </body>
</html>

Thanks
0
 

Author Comment

by:kishore_peddi
ID: 20337364
BTW: I have tried like this:

<html>
      <body>
     
      for $x in doc("Books.xml")/bookstore/book
      where $x/price>30
      order by $x/title
      return $x/title
     
      </body>
</html>

Thanks
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 20337569
As I said, you can't do this in a browser
there simply is no XQuery support in a browser
so I can't make your example work
you need a special XQuery processor for that
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XML Paring  Error - Premature end of file. 7 101
Trouble parsing soap xml result 3 51
XML to Excel using XSL - formatting 3 33
XML response optional elements 12 41
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question