|
INTERVIEW QUESTIONS
XML
XQUERY
DETAILS
Question: How to use FLWOR expression given by XQuery in XML data?
Answer: We use FLWOR expression with XQuery like that,
for $a in doc("bookmart.xml")/bookstore/book where $a/price<150 return $a/title
We use above expression to select all title elements in bookmart element from bookstore element those has price smaller than 150. Output: <title lang="en">Jungle Book</title> <title lang="en">The Book of the Thousand Nights and a Night </title> We can also acheive this by using path expression like that, doc("bookmart.xml")/bookstore/book[price<150]/title
Now, We can also sort this like that, for $a in doc("books.xml")/bookstore/book where $a/price<150 order by $a/title return $a/title
output: <title lang="en">Jungle Book</title> <title lang="en">The Book of the Thousand Nights and a Night </title> Where, for : is used to select all book elements from bookstore into variable $a. where : is used to select only those book elements with a price element those are less than 150. order by : is used to inform that sorting is performed by title element. return : used to return the title elements.
|
|
|
Category |
XQuery Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 6904 users |
Added on |
4/29/2014 |
Views |
67458 |
Rate it! |
|
|
Question:
How to use FLWOR expression given by XQuery in XML data?
Answer:
We use FLWOR expression with XQuery like that,
for $a in doc("bookmart.xml")/bookstore/book where $a/price<150 return $a/title
We use above expression to select all title elements in bookmart element from bookstore element those has price smaller than 150. Output: <title lang="en">Jungle Book</title> <title lang="en">The Book of the Thousand Nights and a Night </title> We can also acheive this by using path expression like that, doc("bookmart.xml")/bookstore/book[price<150]/title
Now, We can also sort this like that, for $a in doc("books.xml")/bookstore/book where $a/price<150 order by $a/title return $a/title
output: <title lang="en">Jungle Book</title> <title lang="en">The Book of the Thousand Nights and a Night </title> Where, for : is used to select all book elements from bookstore into variable $a. where : is used to select only those book elements with a price element those are less than 150. order by : is used to inform that sorting is performed by title element. return : used to return the title elements. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How to perform operation on node using XQuery function in XML?Explain with an example?
|
View Answer
|
|
WHich type of problems we can solved with XQuery?
|
View Answer
|
|
What is XQuery?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All XQuery Interview Questions & Answers - Exam Mode /
Learning Mode
|