1

I'm working on a little project for school. This project asks me to show that I'm capable of using various processing techniques of XML. Now, in my project I work with the Sedna database manager in which I keep user records and I would like to update some of these user records through XQuery (I use the PHP API to send the queries to the database through the PHP Api provided by the Sedna Developers team). Imagine I have the following database content for the user records:

<?xml version="1.0" encoding="UTF-8"?>

<users>
    <user id="admin" admin="true">
        <email>admin@admin.com</email>
        <password>123456789</password>
        <firstname>The</firstname>
        <lastname>Stig</lastname>
        <gender>male</gender>
        <subscriptions>
        </subscriptions>
    </user>
    <user id="prosper" admin="false">
        <email>prosper@localhost.com</email>
        <password>123456789</password>
        <firstname>Strange</firstname>
        <lastname>Figure</lastname>
        <gender>male</gender>
        <subscriptions>
        </subscriptions>
    </user>
</users>

Now, I my intention here is to update, for example, prosper's userrecord. In this record I would like to, for example, change his firstname and email, but keeping the rest unchanged. I have tried to use the following query, but after sending the query, it changes the document order of the userrecord for some reason I don't understand (I think it inserts the attributes nodes of the user record as childnodes). This is the query I use to update the user:

UPDATE replace $user in doc("users")//user[@id="prosper"]
with
<user>{($user/@*)}
<email>strange.figure@localhost.com</email>
{($user/node()[password])}
<firstname>Familiar</firstname>
<lastname>Figure</lastname>
<gender>male</gender>
{($user/node()[subscriptions])}</user>

Now, the problem this query gives me, is that when I try to ask the user's information after the update, I rely on the same order of child nodes have from before the update, but this query changes the order.

Is there someone skilled enough to help me with this problem?

I thank you for your time.

Shcheklein
  • 5,979
  • 7
  • 44
  • 53
Jan Discart
  • 167
  • 1
  • 1
  • 13
  • Jan, your example works (document order between user elements is preserved after replace) for me on Sedna 3.4.66. Can you provide other details to reproduce your problem? – Shcheklein Aug 15 '11 at 16:31
  • Hi Ivan. The document order between the user records is indeed preserved, but the problem lies within the updated userrecord. I have a form in which I let my PHP script fill in the user's information. The user may update this information, and save it. But after the update, when showing that same form, the user's information is not showing correctly. After the update is performed, in the textarea where the firstname should be, the last name is filled in, the textarea where the lastname should be, the gender is filled in. So something inside the userrecord is changed and I can't see why. – Jan Discart Aug 16 '11 at 08:06
  • Jan, see my answer below. Anyway, how do you bind values with fields? – Shcheklein Aug 16 '11 at 10:00

1 Answers1

0

Jan, if you want to get password node you should change your XPath (your current expression {($user/node()[password])} is not what you think):

{$user/password}

the same true for subscriptions:

{$user/subscriptions}

It can be written as one expression with predicate:

{$user/node()[local-name(.) = ('password', 'subscriptions')]}
Shcheklein
  • 5,979
  • 7
  • 44
  • 53
  • You are right. I was not aware of what $user/node()[password] meant. I based that query on what I found on the sedna documentation webpage. Your solution works fine. Thank you very much for your help. – Jan Discart Aug 16 '11 at 18:43