向 xml 添加大量标签的最佳方法?
我需要向 xml 文件添加大量标签。该文件是 Openmediavault 系统 (Debian) config.xml 文件。
具体来说,我需要通过命令行通过 SMB 共享硬盘驱动器。我考虑过通过 SSH 命令或任务计划程序中的脚本来完成此操作。但我要补充的内容相当广泛。我怎样才能做到呢?有没有办法使用 xmlstarlet 来做到这一点?我还没有找到添加这么多标签的简单方法。让我们看看你能否给我一个想法。
我必须将所有这些标签放入
标签中,
<share>
<uuid>0be7e06a-a888-436d-8088-5ec63963vf5</uuid>
<enable>1</enable>
<sharedfolderref>626db680-b317-42b9-a312-d30392bd5re4</sharedfolderref>
<comment></comment>
<guest>no</guest>
<readonly>0</readonly>
<browseable>1</browseable>
<recyclebin>1</recyclebin>
<recyclemaxsize>0</recyclemaxsize>
<recyclemaxage>0</recyclemaxage>
<hidedotfiles>1</hidedotfiles>
<inheritacls>1</inheritacls>
<inheritpermissions>0</inheritpermissions>
<easupport>0</easupport>
<storedosattributes>0</storedosattributes>
<hostsallow></hostsallow>
<hostsdeny></hostsdeny>
<audit>0</audit>
<timemachine>0</timemachine>
<extraoptions></extraoptions>
</share>
我尝试以这种方式添加它,在 subnode.xml 中我已插入我想在共享标签中添加什么,但它不起作用,它向我显示了 xml 的内容并且不对其进行编辑。
sudo xmlstarlet ed -a "//config/services/smb/shares/" -t elem -n share \ -v "$(xmlstarlet sel -t -c '//share/*' subnode.xml)" config.xml\ | xmlstarlet unesc
I need to add a considerable number of tags to an xml file. The file is the Openmediavault system (Debian) config.xml file.
Specifically I need to share a hard drive via SMB by command line. I've thought about doing it by SSH commands or a script in task scheduler. But the content that I have to add is quite extensive. How could I do it? Is there a way to do it using xmlstarlet? I haven't found easy ways to add so many tags. Let's see if you can give me an idea.
I have to put all these tags inside the <smb></smb>
tag
<share>
<uuid>0be7e06a-a888-436d-8088-5ec63963vf5</uuid>
<enable>1</enable>
<sharedfolderref>626db680-b317-42b9-a312-d30392bd5re4</sharedfolderref>
<comment></comment>
<guest>no</guest>
<readonly>0</readonly>
<browseable>1</browseable>
<recyclebin>1</recyclebin>
<recyclemaxsize>0</recyclemaxsize>
<recyclemaxage>0</recyclemaxage>
<hidedotfiles>1</hidedotfiles>
<inheritacls>1</inheritacls>
<inheritpermissions>0</inheritpermissions>
<easupport>0</easupport>
<storedosattributes>0</storedosattributes>
<hostsallow></hostsallow>
<hostsdeny></hostsdeny>
<audit>0</audit>
<timemachine>0</timemachine>
<extraoptions></extraoptions>
</share>
I have tried to add it in this way, in subnode.xml I have inserted what I wanted to add inside the shares tags, but it does not work, it shows me the content of the xml and does not edit it.
sudo xmlstarlet ed -a "//config/services/smb/shares/" -t elem -n share \ -v "$(xmlstarlet sel -t -c '//share/*' subnode.xml)" config.xml\ | xmlstarlet unesc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 XSLT 转换:
第一个模板规则是默认规则;它说复制元素不变。第二条规则针对
smb
元素覆盖此规则:它表示将newContent.xml
的副本插入到smb
元素中。Use an XSLT transformation:
The first template rule is a default rule; it says copy elements unchanged. The second rule overrides this for
smb
elements: it says insert a copy ofnewContent.xml
into thesmb
element.