Storing and removing a doc in the db
Posted by mholmes on 17 Dec 2010 in Activity log
Note to self: this is a simple, tested way of storing a document in the db:
declare default element namespace "http://www.tei-c.org/ns/1.0"; declare namespace xdb="http://exist-db.org/xquery/xmldb"; declare namespace util="http://exist-db.org/xquery/util"; let $doc := <doc><test>My test doc</test></doc>, $coll := collection('/db/coldesp/oai/records/') return xdb:store($coll, 'test.xml', $doc)
This will delete a document:
return xdb:remove('/db/coldesp/oai/records/', 'test.xml')
This snippet will delete a document if it exists, then replace it:
let $remove := if (fn:doc('/db/coldesp/oai/records/test.xml')) then xdb:remove('/db/coldesp/oai/records/', 'test.xml') else (), $doc := <doc><test>My test doc 2</test></doc>, $coll := collection('/db/coldesp/oai/records/') return xdb:store($coll, 'test.xml', $doc)