0

I am trying this XQuery on BaseX:

xquery //Bookstore/Book/Title

Although in the tutorial at 2:01 it works in me it throws this error:

Error:
Stopped at ., 1/2:
[XPDY0002] No context item defined to evaluate 'root()'.
Compiling:
- simplifying descendant-or-self step(s)
Query:
//Bookstore/Book/Title
Optimized Query:
root()/descendant::Bookstore/Book/Title
Query plan:
<QueryPlan>
  <CachedPath>
    <Root/>
    <IterStep axis="descendant" test="Bookstore"/>
    <IterStep axis="child" test="Book"/>
    <IterStep axis="child" test="Title"/>
  </CachedPath>
</QueryPlan>

I have searched to the Web and i really cannot understand what to do. Why is this happening since i have the root element in the command which is Bookstore. I am trying to query this:

<Bookstore>
   <Book ISBN="ISBN-0-13-713526-2" Price="85" Edition="3rd">
      <Title>A First Course in Database Systems</Title>
      <Authors>
         <Author>
            <First_Name>Jeffrey</First_Name>
            <Last_Name>Ullman</Last_Name>
         </Author>
         <Author>
            <First_Name>Jennifer</First_Name>
            <Last_Name>Widom</Last_Name>
         </Author>
      </Authors>
   </Book>
   <Book ISBN="ISBN-0-13-815504-6" Price="100">
      <Title>Database Systems: The Complete Book</Title>
      <Authors>
         <Author>
            <First_Name>Hector</First_Name>
            <Last_Name>Garcia-Molina</Last_Name>
         </Author>
         <Author>
            <First_Name>Jeffrey</First_Name>
            <Last_Name>Ullman</Last_Name>
         </Author>
         <Author>
            <First_Name>Jennifer</First_Name>
            <Last_Name>Widom</Last_Name>
         </Author>
      </Authors>
      <Remark>
      Buy this book bundled with "A First Course" - a great deal!</Remark>
   </Book>
   <Book ISBN = "ISBN-0-11-222222-3" Price="50">
      <Title>Jennifer's Economical Database Hints</Title>
      <Authors>
         <Author>
            <First_Name>Jennifer</First_Name>
            <Last_Name>Widom</Last_Name>
         </Author>
      </Authors>
   </Book>
   <Magazine Month="January" Year="2009">
       <Title>National Geographic</Title>
   </Magazine>
   <Magazine Month="February" Year="2009">
       <Title>National Geographic</Title>
   </Magazine>
   <Magazine Month="February" Year="2009">
       <Title>Newsweek</Title>
   </Magazine>
</Bookstore>
wst
  • 11,681
  • 1
  • 24
  • 39
ExoticBirdsMerchant
  • 1,466
  • 8
  • 28
  • 53

1 Answers1

1

It looks like you didn't open the document (database), thus the document root root() is not defined. From the BaseX documentation on creating databases:

  • Console: CREATE DB db /path/to/resources will add initial documents to a database
  • GUI: Go to Database → New, press Browse to choose an initial file or directory, and press OK

After creating a database, it is opened automatically, otherwise use the console command OPEN [db] or in the GUI Database → Open & Manage.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
  • You are an exams-life-saver! – ExoticBirdsMerchant Jun 09 '14 at 15:58
  • Just out of curiosity: this is the second question within an hour referring to that coursera-topic, but they don't mention BaseX in there at all. Is there any other source recommending BaseX (which I think is a great tool for learning XQuery, although I should add a disclaimer of being somewhat affiliated with the BaseX developers)? – Jens Erat Jun 09 '14 at 16:05
  • Well the professor does not state what tool she is using so in the discussion forums of the Course there are many students that they say that they have opted to use BaseX as their tool. I personally find it very irresponsible for the tutor not putting a link with the software she used. – ExoticBirdsMerchant Jun 09 '14 at 16:26