替换XML文件中的动态内容 [英] Replace dynamic content in XML file
问题描述
快速摘要:我需要创建一个Bash脚本来改变每周自动节点中的文本。该脚本将匹配节点和替换里面的文字它们(如果可能的话)?我会怎么做呢?
Quick Summary: I need to create a Bash script to change the text within a node automatically every week. The script will match the node and replace the text inside them (if this is possible)? How would I do this?
龙摘要:
我的主机里面有商店,每个在/ ShowcaseStandalone / FFS存储/目录下自己的.xml文件一个的Minecraft服务器。每个星期天我的服务器重新启动并执行多个命令到终端重置几件事情。我试图做出改变的一件事是的商店之一。我想改变的节点&lt文本; itemstack>并在节点&lt文本;价格&gt ;.我只是希望把来自不同文件夹中的.txt文件的文本,并将其插入到该节点。的问题是,在该节点的文本将每周更换。有什么办法使用bash来代替两个节点中的一个特定的行或文字?
Long Summary: I host a Minecraft server which has shops, each of which have their own .xml file in the /ShowcaseStandalone/ffs-storage/ directory. Every Sunday my server restarts and executes several commands into the terminal to reset several things. One thing that I am trying to make change is one of the shops. I am wanting to change the text in the node <itemstack> and the text in the node <price>. I am simply wanting to take text from a .txt file in a different folder, and insert it into that node. The problem is, that the text in the node will change every week. Is there any way to replace a specific line or text within two nodes using bash?
XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<scs-shop usid="cac8480951254352116d5255e795006252d404d9" version="2" type="storage">
<enchantments type="string"/>
<owner type="string">Chadward27</owner>
<world type="string">Frisnuk</world>
<itemStack type="string">329:0</itemStack>
<activity type="string">BUY</activity>
<price type="double">55.0</price>
<locX type="double">487.5</locX>
<locY type="double">179.0</locY>
<locZ type="double">-1084.5</locZ>
<amount type="integer">0</amount>
<maxAmount type="integer">0</maxAmount>
<isUnlimited type="boolean">true</isUnlimited>
<nbt-storage usid="23dffac5fb2ea7cfdcf0740159e881026fde4fa4" version="2" type="storage"/>
</scs-shop>
操作系统: Linux操作系统Ubuntu 12.04
Operating System: Linux Ubuntu 12.04
推荐答案
您可以使用 xmlstarlet
编辑 XML
文件中壳
是这样的:
You can use xmlstarlet
to edit a XML
file in a shell
like this :
xmlstarlet edit -L -u "/scs-shop/price[@type='double']" -v '99.66' file.xml
注意
-
/ SCS-店/价格[@类型='双']
是的 Xpath的前pression - 看
xmlstarlet ED --help
"/scs-shop/price[@type='double']"
is a Xpath expression- see
xmlstarlet ed --help
这篇关于替换XML文件中的动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!