问题
I am trying to use BaseX
to run an XQuery
with no success. I have tried typing commands like:
doc("Bookstore.xml")//Bookstore
//Bookstore
XQUERY[//Bookstore]
and i am getting these error messages:
Stopped at C:/tools/libxml/file, 1/32:
Unknown command: doc("Bookstore.xml")//Bookstore. Try HELP.
Stopped at C:/tools/libxml/file, 1/12:
Unknown command: //Bookstore. Try HELP.
Stopped at C:/tools/libxml/file, 1/20:
Unknown command: XQUERY[//Bookstore]. Try HELP.
whenever i try to hit Execute Query. How can i make this actually work? I am watching the Stanford tutorials but those commands that are showing there do not work on BaseX
.
Below you can just see the file
i am trying to query for educational purposes.
<?xml version="1.0" ?>
<!--Bookstore with no DTD-->
<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">
<Remark>
Buy this book bundled with "A First Course" - a great deal!
</Remark>
<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>
</Book>
</Bookstore>
EDIT

回答1:
If you're running BaseX commands, for example in the BaseX command line client or the GUI command input line, you have to prefix the query with the command XQUERY
. BaseX commands are separated by whitespace from their parameters, so in your case, run any of
XQUERY //Bookstore
XQUERY doc('Bookstore.xml')//Bookstore
depending on whether the document (database) is already opened or not.
If you're using the BaseX GUI, you can also directly put the query into the query window, then you don't need the XQUERY
command prefix at all and directly one of those (like above)
//Bookstore
//doc('Bookstore.xml')//Bookstore

Anyway: You'll probably want to use /Bookstore
instead: at least if I'm guessing correctly and you want to query the root element, and not all <Bookstore/>
elements in the whole document.
来源:https://stackoverflow.com/questions/24121601/execute-xquery-with-basex