Question

I'm new in eXist-db. What I want to do is to store LARGE amount of data in XML format into a native XML database for fast processing (searching/updating/etc.) But unfortunately, the documentation provided doesn't explain clearly on how to save/modify data into a persistent database (or back to XML files).

Below is roughly what I want to do in eXide. The lines that I don't know how to do are commented in questions Q1, Q2, and Q3:

xquery version "3.0";

let $data := doc('file:///c:/eXist/database.xml')

let $newdata := doc('file:///c:/import/newdata.xml')

(: Q1. How to do merging of data like below? :)
update insert $newdata into $data

(: Q2. How to save the changes back to database.xml? :)
doc('file:///c:/eXist/database.xml') := $data

let $result := <result>
{
    for $t in $data/book/title
    where $t/../publisher = 'XYZ Company'
    return $t
}
</result>

(: Q3 How to save query result to a new file? :)
doc('file:///c:/export/XYZ Company Report.xml') := $result

Thanks in advance.

Was it helpful?

Solution

Your doc() functions all point to files on your file system, which indicates a misunderstanding about how one works with XML data with eXist-db. When working with eXist-db, though, all manipulations of XML data happen in the database. Thus, you need to first store the XML data in the database, and then you can perform your manipulations. Then, if needed, you can serialize the data back out onto the file system.

To store data into the database, see Getting Data into eXist-db.

To merge data, see XQuery Update Extensions.

To serialize the data back out onto the file system, see the function documentation for file:serialize().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top