2

I'm running eXist-db 3.6.1 on CentOS 7.4.1708 (Core), Java(TM) SE Runtime Environment (build 1.8.0_152-b16). I want to be able to add a new record after the last one in an persons.xml structured like so:

<person xml:id="pe0472"> [...] </person>
<person xml:id="pe0473"> [...] </person>

I have a html form inside a function in my app.xql called via data-template in editpers.html which grabs the data:

declare function app:newpers($node as node(), $model as map(*), $searchkey as xs:string?)

{

let $surname := doc(concat($config:app-root, '/input/persons.xml'))//tei:listPerson/tei:person[@xml:id=$searchkey]/tei:persName/tei:surname

[...]

return

<div class="container">

<form action="add.html" method="POST">  

<div class="form-group">

Surname:<br/>
<input type="text" name="surname" value="{$surname}"/>
[...]
<input class="btn btn-default" type="submit" value="Submit"/>
</div>
</form>
</div>
};

The form's submit sends to add.html, which references to the app:addpers function via data-template:

declare function app:addpers($node as node(), $model as map(*)) {

let $peid := request:get-parameter('peid', '')
let $surname := request:get-parameter('surname', '')
[...]
let $on-disk := doc(concat($config:app-root, '/input/persons.xml'))

let $insert := update insert

<person xml:id="{$peid}" >
<persName xmlns="http://www.tei-c.org/ns/1.0">
<surname>{$surname}</surname>
[...]
</persName>
</person> 

following $on-disk//tei:person[@xml:id][last()]

return

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Added</title>
    </head>
    <body>
         <div>
            <h3>Success!</h3>
        </div>
    </body>
</html>

};

I get the nice message, and if I open the master persons.xml file in oXygen I can see the new record nicely added. Nevertheless it doesn't show up in my webpage which shows all the records via this query:

declare function app:listPers($node as node(), $model as map(*)) {

for $person in doc(concat($config:app-root, '/input/persons.xml'))//tei:listPerson/tei:person
    return

    <tr>
        <td>{$person/tei:persName/tei:forename}</a></td>
    </tr>    
};

This shows all the records but not the latest one added via the app:addpers function. Refreshing the cache on the browser, which helps when I update values on existing records with:

let $update := update value $on-disk//tei:person[@xml:id eq $peid]/tei:persName/tei:surname with $surname

(the edited records are not shown until I clear the cache) doesn't help this time.

In order to show the new records on my front-end (app:listPers) is to do something stupid to the master file in oXygen (say, add and delete a space anywhere, then save it), and the new record will magically appear on my browser's page. Is this expected behaviour? I find it very puzzling and I cannot think of anything else I can try to fix this issue.

I have tested it on Firefox 58.0.1 and Safari 11.0.3.

HBMCS
  • 686
  • 5
  • 25
  • Update: it might not be the xml:id alone. I've noticed that it is sufficient to delete and rewrite a single letter of any field af any line of the .xml file in oXygen (even previous records!), and the latest records show up. It almost looks as though eXist-db ignores the updates to the file until it is edited/saved inside oXygen. This sounds like a weird behaviour to me, and definitely not what one would expect. Is there any way I can let eXist to 'see' the added records correctly without having to open oXygen and edit/save the file there? – HBMCS Feb 06 '18 at 00:35
  • Also, I need to refresh the cache of the browser in order to see records I update with `update value`. Do you think this is related to my issue? It's inconvenient to have to hit shift-cmd-r after each time I edit something via the html forms through the browser in order to see the updated version of my records. – HBMCS Feb 06 '18 at 00:58
  • Unfortunately there is not enough detail in your question to answer it. Please provide a minimal, self-contained, reproducible test and specify your eXist version number. Please also note any errors in exist.log that correspond to the actions. – Joe Wicentowski Feb 06 '18 at 17:12
  • @joewiz, I have also deleted the custom user I created and authenticated as administrator (in the end I'll want to give each of the editing-collaborators their user/password). So, even doing everything as administrator I get the very same issue, therefore, I guess, it's not an issue related to authentication. I don't know what else to think! – HBMCS Feb 07 '18 at 14:02
  • I have also repaced `for $person in doc(myfile)//tei:listPerson/tei:person` with `for $person in xmldb:document(myfile)//tei:listPerson/tei:person` - same issue. – HBMCS Feb 07 '18 at 14:31
  • I have partially solved the issue by moving the appended `xmlns="http://www.tei-c.org/ns/1.0"` from the `persName` element to `person` element, thanks to a hint by @joewiz. Now the new records are showing the the lising page. Nevertheless, I still have to force a clear browser cache each and every time I visit the page in order to see the updates. Adding ` ` on the header doesn't help. – HBMCS Feb 08 '18 at 08:57

1 Answers1

0

My workaround, for now, is to add a

    <script type="text/javascript">
        window.addEventListener('load', function (e) {
            window.applicationCache.addEventListener('updateready', function (e) {
                window.location.reload(true);
                }, false);
            console.log("loaded");
        }, false);
    </script>

to the head of the affected pages, which forces a no-cache reload of the page without having to do it manually.

HBMCS
  • 686
  • 5
  • 25