Sedna 中的 XQuery 更新替换

发布于 2024-11-29 12:49:40 字数 2022 浏览 1 评论 0原文

我正在为学校做一个小项目。这个项目要求我证明我有能力使用 XML 的各种处理技术。现在,在我的项目中,我使用 Sedna 数据库管理器,在其中保存用户记录,并且我想通过 XQuery 更新其中一些用户记录(我使用 PHP API 通过 PHP API 提供的 PHP API 将查询发送到数据库) Sedna 开发团队)。 想象一下,我有以下用户记录的数据库内容:

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

<users>
    <user id="admin" admin="true">
        <email>[email protected]</email>
        <password>123456789</password>
        <firstname>The</firstname>
        <lastname>Stig</lastname>
        <gender>male</gender>
        <subscriptions>
        </subscriptions>
    </user>
    <user id="prosper" admin="false">
        <email>[email protected]</email>
        <password>123456789</password>
        <firstname>Strange</firstname>
        <lastname>Figure</lastname>
        <gender>male</gender>
        <subscriptions>
        </subscriptions>
    </user>
</users>

现在,我的目的是更新,例如,prosper 的用户记录。例如,在此记录中,我想更改他的名字和电子邮件,但保持其余部分不变。 我尝试使用以下查询,但是在发送查询后,它由于某种我不明白的原因更改了用户记录的文档顺序(我认为它会将用户记录的属性节点作为子节点插入)。 这是我用来更新用户的查询:

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

现在,这个查询给我带来的问题是,当我尝试在更新后询问用户的信息时,我依赖于更新前的子节点的相同顺序,但是这个查询改变了顺序。

有足够熟练的人来帮助我解决这个问题吗?

我感谢您抽出时间。

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>[email protected]</email>
        <password>123456789</password>
        <firstname>The</firstname>
        <lastname>Stig</lastname>
        <gender>male</gender>
        <subscriptions>
        </subscriptions>
    </user>
    <user id="prosper" admin="false">
        <email>[email protected]</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>[email protected]</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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帥小哥 2024-12-06 12:49:40

Jan,如果你想获取 password 节点,你应该更改你的 XPath (你当前的表达式 {($user/node()[password])} 不是你想象的那样):

{$user/password}

对于 subscriptions 也是如此:

{$user/subscriptions}

它可以写成带有谓词的一个表达式:

{$user/node()[local-name(.) = ('password', 'subscriptions')]}

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')]}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文