Solved

Why XQUERY is needed when XPATH is already there ?

Posted on 2007-11-22
6
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 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