XQuery - 根据其子元素处于“禁止”状态来删除节点列表

发布于 2024-08-18 00:28:20 字数 567 浏览 1 评论 0原文

我对 XQuery 完全是菜鸟,但在开始深入研究之前,我想向一些专家询问我是否正在寻找正确的方向。

问题: 一个巨大的 xml 文件,其中包含大量用户及其访问信息(密码访问权限等),如下所示:

<user>
    <name>JC1234</name>
    <password>popstar</password>
    <accesslevel>0</accesslevel>
</user>
<user>
    <name>AHkl</name>
    <password>Rudy10!</password>
    <accesslevel>2</accesslevel>
</user>

我有一个用户名列表(csv 文件),需要从该巨大的 xml 文件中删除。 结果应该是一个新的 xml 文件,其中没有那些已删除的用户......

这对于 XQuery 可行吗? 欢迎任何关于快速而肮脏的解决方案的建议!

I am a total noob with XQuery, but before at start digging deep into it, i'd like to ask some experts advice about whether i am looking at the correct direction.

The problem:
A huge xml file which contains a whole lot of users and their access information (password access rights and so on) example below:

<user>
    <name>JC1234</name>
    <password>popstar</password>
    <accesslevel>0</accesslevel>
</user>
<user>
    <name>AHkl</name>
    <password>Rudy10!</password>
    <accesslevel>2</accesslevel>
</user>

i have a list of user names (csv file) that i need to remove from that huge xml files.
the result should be a new xml file wihtout those removed users....

is this feasable with XQuery?
any advice for a quick and dirty solution is welcomed!

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

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

发布评论

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

评论(1

成熟稳重的好男人 2024-08-25 00:28:20

尽管大多数实现都有未解析的文本函数或类似函数,但在普通 XQuery 1.0 中没有加载 CSV 文件的标准方法。如果没有,文件的内容可以作为参数传入。

可以使用 tokenize 函数解析 CSV 文件:

declare variable $names = tokenize(unparsed-text("banned.csv"), ",")

并且实际查询非常简单。假设您的文档是一个仅包含 节点列表的片段,那么查询就很简单。

doc("users.xml")/user[not(name=$names)]

但是,如果 XML 文件包含大量其他数据,那么您可能会发现 XSLT 的模板功能更有用。

There is no standard way of loading a CSV file in vanilla XQuery 1.0, although most implementations have an unparsed-text function or similar. If not the contents of the file can be passed in as a parameter.

The CSV file can be parsed using the tokenize function:

declare variable $names = tokenize(unparsed-text("banned.csv"), ",")

And the actual query is quite straightforward. Assuming your document is a a fragment containing just a list of <user /> nodes then the query is simply

doc("users.xml")/user[not(name=$names)]

If however the XML file contains a lot of other data then you may find XSLT's templating facilities more useful.

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