XQuery - 根据其子元素处于“禁止”状态来删除节点列表
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管大多数实现都有未解析的文本函数或类似函数,但在普通 XQuery 1.0 中没有加载 CSV 文件的标准方法。如果没有,文件的内容可以作为参数传入。
可以使用 tokenize 函数解析 CSV 文件:
并且实际查询非常简单。假设您的文档是一个仅包含
节点列表的片段,那么查询就很简单。但是,如果 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:
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 simplyIf however the XML file contains a lot of other data then you may find XSLT's templating facilities more useful.