Database Reference
In-Depth Information
This results in a response that starts with the element:
<exist:result
xmlns:exist=
"http://exist.sourceforge.net/NS/exist"
exist:hits=
"567"
exist:start=
"11"
exist:count=
"10"
exist:session=
"23"
>
Again, we have omitted the entire response body for brevity, but the important thing
to note here is that the REST Server is now returning the second page of results—that
is,
10
results (
count
attribute) starting from position
11
(
start
attribute) in the
cached result set.
We include the actual query in each request we send, in case the
cached query result set has expired and the query has to be recom‐
puted. This way, we know that we will always get the response,
whether it's served from the cache or calculated. To retrieve further
pages, simply repeat the second query, adjusting the
start
attribute each time.
Updating the database
You may update nodes within documents in eXist via the REST Server API, by
POST
ing XUpdate documents to the URI that indicates the collection or document
context within the database to update. In addition, you may manually specify individ‐
ual operations against other documents or collections in your XUpdate documents
by using the XQuery
fn:doc
or
fn:collection
functions. If the document you are
updating does not allow write access by
other
users, then you will also need to pro‐
vide a username and password for an account that does have write access.
Let's look at how we would apply an XUpdate document to the document
/db/some-
document.xml
in eXist via the REST Server API:
<hello/>
This XUpdate document will insert an element called
name
with the text
Adam
into
each
hello
element that it finds:
<?xml version="1.0" encoding="UTF-8"?>
<xupdate:modifications
version=
"1.0"
xmlns:xupdate=
"http://www.xmldb.org/xupdate"
>
<xupdate:append
select=
"/hello"
>
<name>
Adam
</name>
</xupdate:append>
</xupdate:modifications>
The following cURL command would apply the XUpdate document stored at
/tmp/
add-name.xupdate
to the XML document
/db/some-document.xml
in eXist:
curl -X POST -H
'Content-Type: application/xml'
--data-binary @/tmp/add-name.xupdate
http://aretter:12345@localhost:8080/exist/rest/db/some-document.xml
Search WWH ::
Custom Search