?
Solved

Why XQUERY is needed when XPATH is already there ?

Posted on 2007-11-22
6
Medium Priority
?
402 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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 2000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

800 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