Changes

Jump to navigation Jump to search
168 bytes removed ,  09:37, 12 January 2011
no edit summary
==First Operations==
To get familiar with to know BaseX , we suggest advise to execute run some of the following basic operationsto see how it works andget your first indentations.
===Create a database===
* To In order to create a database you need an XML a xml-document, e.g. [http://www.w3.org/XML/Binary/2005/03/test-data/Over100Over100K/factbook.xml factbook.xml].<br/>* Save this document to the /basex directory.* On the client terminal run: :<code>: > create db factbook factbook.xml
</code>
<br/>
''factbook'' - is the name of the database <br/>
''factbook.xml'' - is the xml file, which is used to create the database<br/>
: ''factbook'' - is the name of the database <br/>: ''factbook.xml'' - is the xml file, which is used to create the database<br/>  If everything works you see , this message will appear, the following lines:time might differ.
<pre>Database 'factbook' created in 1950.83 ms.
</pre>
; Where is the database stored?Databases are It is stored in the BaseXData directory which is located in your home folder. Depending on your operating system the location of your home folder variesdirectory. For example, on a mac In my case it's in /Users/John, if your name is JohnJohnDoe/BaseXData/factbook.
===Execute a query===
The [[Commands|To run a query the xquery]] command lets is used. After '''xquery''' you can insertany valid xquery you run a querylike.<br/>* For example, this This query returns all country nodes the countries in the currently opened database.:<code>: > xquery //country
</code>
<br/>
* You If you wish, you can also save your query in a file, and run queries in filesit on basex.:<code>: > run /Users/JohnpathToQuery/query.xqtxt
</code>
===Create a new another database, switch between databases===Now we will create an another database. You can find get the example xml document from here: [http://phobos101.inf.uni-konstanz.de/basex/demo]. * Create the new database, named 'xmark'.:<code>: > create db xmark xmark.xml
</code>
* Set To set the new database xmark as the context(the active, opened database), use::<code>: > open xmark
</code>
* Now you can easily execute queries on simply type your new databasexquery::<code>: > xquery //people/person/name
</code>
===Switch If you want to query the factbook database===* You you can access it by explicitly query the factbook database naming it with the doc()-funtion, no matter what the current context isfunction.:<code>: > xquery doc("factbook")//country
</code>
* Otherwise, If you want to set the factbook database as the current context, execute the followingyou can use::<code>: > open factbook
</code>
* To list the current contextsee which database is opened, typeuse::<code>: > show databases
</code>
 
That yields the following lines:
 
<pre>
1 opened database(s):
- factbook (1x)
</pre>
===Close or delete a database===
* To [[Commands|If you want to close]] the current context opened database , simple type: :<code>: > close
</code>
* Use the [[Commands|drop]] command If you want to delete the xmark database, use::<code>: > drop db xmark
</code>
===Create a collection===
'''What is a collection?'''
With BaseX you can group documents into one logical collection. A collection is a database that contains two or more documents. Collections accept You can put any type of XML documentsinto the collection, regardless of their structure.
Let's Now we will add the xmark.xml document to the factbook database to ,and thus create a collection. The collection will keep the name of the original factbook database remains.
* First make sure factbook is opened::<code>: > open factbook
</code>
* Now add the xmark.xml document: :<code>: > add xmark.xml
</code>
===Delete a document from a collection===
* Deleting a document from a collection is very easy, just type::<code>: > delete xmark.xml
</code>
Make sure N.B. The collection has to be the context i.e. the collection database which contains the xmark.xml document is has to be opened.
===Delete a collection===
Deleting a collection is the same as deleting a database.
 * To If you want to delete the collection factbook, type::<code>: > drop factbook
</code>
===Get Getting information about the server===Several commands help to explore the state of a server. For a complete list visit the [[Commands|commands section]]. * To see all databases on the serverin BaseX, type::<code>: > list
</code>
* To see which database is currently opened, type::<code>: > show databases
</code>
* To see the general information of the opened database, type::<code>: > info
</code>
* To see the users in BaseX, type::<code>: > show users
</code>
===Backup and RestoreRestrore===
To backup your database, type:
:<code>
</code>
'''Where is the backup-file stored?'''
The backup-file is stored in the database BaseXData directory, which is in your home directory.The file is named <code>factbook-timestamp.zip</code> (<code>db_name-timestamp.zip</code>).
To restore the database the file with the newest timestamp is taken.
bueraucrat, Bureaucrats, editor, reviewer, Administrators
907

edits

Navigation menu