How to edit a xml file via browser with eXist-db and xsltForms

342 Views Asked by At

I am relatively new to eXist-db. I have already built an application which displays XML documents in the browser, and implemented a basic search.

I have an .xml file which functions as a database; it contains records such as:

<person xml:id="pe0001">
    <persName>
        <surname>Name</surname>
        <forename>Surname</forename>
    </persName>
</person>

I would like to be able to edit this file via the browser; for instance, edit a person's name, or add a new record.

I have gone through eXist-db documentation, looked at the examples, read wikibooks - I haven't found what I need yet. I just need a text area in which someone can input/edit some text which will be pushed (using PUT, I guess) into the .xml file.

Is XSLTForms the best option for me? Could anyone be so kind to give me some sort of direction/suggestion/example? Thanks!

3

There are 3 best solutions below

0
On BEST ANSWER

Thanks for the downvote :) . Anyway, I have created a .xq file which grabs the id of the node I want to edit with

let $id := request:get-parameter("id", "")

and then returns this html code:

head

     <xf:model>
        <xf:instance id="data-instance" src="my.xml" xmlns="http://www.tei-c.org/ns/1.0" />
        <xf:submission id="read-from-file" method="get"
            action="my.xml" replace="instance" instance="data-instance" />
        <xf:submission id="save-to-file" method="put"
            action="my.xml" replace="instance" instance="data-instance" />
    </xf:model>

body

     <xf:input xmlns="" ref="//tei:person[@xml:id='{$id}']/tei:persName/tei:surname">
        <xf:label>Surname</xf:label>
    </xf:input>
     <xf:input xmlns="" ref="//tei:person[@xml:id='{$id}']/tei:persName/tei:forename">
        <xf:label>Name</xf:label>
    </xf:input>

Once edited the text, the user submits it via the following button:

    <xf:submit submission="save-to-file">
        <xf:label>Save</xf:label>
    </xf:submit>
0
On

I think for relatively simple records like you've shown as example, good ole HTML forms would be the simplest solution, triggering an XQuery script on the eXist-db side that actually updates the data. XForms, say, offer little gain and there's surely a steep learning curve involved.

0
On

depending on use case, you might want to take a look at how the default documentation app let's users open (and run) an example in eXide (using loadsource.js).

For simple xml editing eXide is plenty capable.