Databases

From BaseX Documentation
Revision as of 16:24, 22 September 2011 by CG (talk | contribs)
Jump to navigation Jump to search

Introduction

In BaseX, there are two kinds of databases. It is possible to have databases with single XML documents and databases with a bunch of XML files, called Collections.

Creation of a database

You can create a database either within the GUI or in the console version of BaseX.

  • GUI: Go to DatabaseNew and then press Browse to choose a file and press OK
  • Console: enter basex -c "CREATE DB dbname /path/to/file"

Collection

Creation of a collection

You can create a collection either within the GUI or in the console version of BaseX.

  • GUI: Go to DatabaseNew and then press Browse to choose a directory and press OK
  • Console: enter basex -c "CREATE DB dbname /path/to/collection"

Manage Collections

Additional to the creation with your choosen xml files you can start with creating an empty collection and then add your xml files to it. Note that the ADD and DELETE commands refer to the currently opened database.

Console:

  • Create an empty database: CREATE DB example
  • Add a document: ADD example.xml
  • Delete a document: DELETE example.xml

GUI: In the GUI you can execute all above operations in the Database menu.

Once you have created a database, you may as well use the BaseX-specific [Database Functions|XQuery Database Functions] to add or delete XML documents:

for $file in file:list("/path/to/xml/documents")
return db:add("database", $file)

Access documents in collections

The XQuery collection() function can be used to access documents in collections:

  • Returning all documents of collection ("dbname"):
    for $doc in collection("dbname") return base-uri($doc)
  • Access a specific document ("test") in collection ("dbname"):
    collection("dbname/test")//*