Introducing Berkeley DB XML
Getting Started with Berkeley DB XML
For dbxml-2.2.13
Chapter I. Overview
Take dbxml-2.2.13 as an example of this chapter, use the dbxml-2.2.13
Basis
BDB XML directly to the user's application in the form of a library, BDB XML also has a command prompt to allow users to access XML documents in a disconnected programming environment, and you can use the command prompt as a management tool for your application.
In the DBD XML, all data is stored in a file that becomes a "container" (containers), BDB XML shell
Provides an easy way to manipulate "containers" and all the DBD functions.
The container can store the entire XML document as a document, or store the nodes separately, and when the whole is stored, the XML document is a "container" or a system file, and when the node is stored, the XML is partitioned into small chunks and stored in the "container".
In node storage mode, the format of the extracted document is the format you store (unless you specify a format output), the difference is how you store it. " Node storage mode provides better performance than the entire document store. All default is node storage mode
Using the shell
Shell command in the bin directory of the BDB XML installation directory, enter the bin directory input Dbxml launch shell
As follows
Bin>dbxml
d ' B ' xml>
BDB XML statements have Single-line and multiline.
BDB XML stores documents in containers, which contain collections of documents, and multiple documents in one container can be structurally different or identical.
To start our BDB XML journey, first create a container, our first example is a simple phone book, the name of the container is phone.dbxml (the extension is not necessarily dbxml, but it is recommended to write)
Dbxml>createcontainer Phone.dbxml
Because the directory we are in is bin>, so Phone.dbxml is created in the bin directory
When the creation is complete, the shell automatically opens the last created container.
Next, enter the XML into the Phone.dbxml
((single quotes) containing the data entered)
Dbxml>putdocument phone1 ' <phonebook> (carriage return)
<name> (carriage return)
<first>Tom</first> (carriage return)
<last>Jones</last> (carriage return)
</name> (carriage return)
<phone type= "Home" >420-203-2033</phone> (carriage return)
</phonebook> ' (space) s (carriage return) (s = end of input)
If successful, the display
Document added,name=phone1
Enter one more record
dbxml> putdocument phone2 ' <phonebook> (carriage return)
<name> (carriage return)
<first>Lisa</first> (carriage return)
<last>Smith</last> (carriage return)
</name> <phone type= "Home" >420-992-4801</phone> (carriage return)
<phone type= "Cell" >390-812-4292</phone> (carriage return)
</phonebook> ' (space) s (carriage return)
If successful, the display
Document added, name = Phone2
Now that there are two records in the Phone.dbxml, several basic XQuery queries based on XPath statements have been applied in the following example, and later there will be more complex XQuery statements.
XPath statements are a major part of the XQuery specification, just as the SELECT statement is in SQL/Note collection ("Phone.dbxml") this statement, we can also simply write as collection () Indicates that our action object is the currently open container.
Dbxml>query ' Collection ("Phone.dbxml")/phonebook/name/last/string ();
Display after successful query
2 objects returned for eager expression '
Collection ("Phone.dbxml")/phonebook/name/last/string () '
Displays the last name found
Dbxml>print
Jones
Smith
So far, the first small experiment has been successful.
Now, let's find Lisa's home phone number.
Dbxml>query ' Collection ("Phone.dbxml")/phonebook[name/first= "Lisa"]/phone[@type = "Home"]/string ()
Display after successful query
1 objects returned for eager expression '
Collection ("Phone.dbxml")/phonebook[name/first = "Lisa"]/phone[@type = "Home"]/string ()
dbxml> Print
420-992-4801
To display all phone numbers that start with 420, you can write
dbxml> Query ' collection ("Phone.dbxml")/phonebook/phone[starts-with (., "420")]/string () '
2 objects returned for eager expression '
Collection ("Phone.dbxml")/phonebook/phone[starts-with (., "420")]/string () '
dbxml> Print
420-203-2032
420-992-4801
The query above returns a portion of the data, just like the SELECT statement, where each query statement contains two parts, one: the container we want to query, we use collection ("Phone.dbxml") to represent the container for the query, two: XPath statements, such as/ Phonebook/name/last/string (); indicates that you want to query all last name;
Understand