Search code examples
xmlxsltxformsexist-dbxsltforms

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


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!


Solution

  • 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>