BaseX XQuery没有定义任何上下文项来评估'root()'

时间:2014-06-09 15:05:25

标签: xml xpath xquery basex

我在XQuery上尝试BaseX

xquery //Bookstore/Book/Title

虽然tutorial at 2:01在我的工作中它会引发这个错误:

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>

我搜索过网络,我真的无法理解该怎么做。为什么会发生这种情况,因为我在root element命令中有Bookstore。我想查询一下:

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

1 个答案:

答案 0 :(得分:1)

看起来您没有打开文档(数据库),因此未定义文档根root()。来自BaseX documentation on creating databases

  
      
  • 控制台: CREATE DB db /path/to/resources会将初始文档添加到数据库
  •   
  • GUI:转到数据库→新建,按浏览选择初始文件或目录,然后按确定
  •   

创建数据库后,它会自动打开,否则使用控制台命令OPEN [db]或GUI数据库→打开&amp;管理。