请问怎么把 open_time=”5.25″ 插到这里面
<lootcontainer name=”reinforcedChestT1″ count=”1″ size=”8,9″ sound_open=”UseActions/chest_tier1_open” sound_close=”UseActions/chest_tier1_close” loot_quality_template=”qualPlus1Template” ignore_loot_abundance=”true”>
<item group=”groupReinforcedChestT1″/>
</lootcontainer>
我是想给房子的最终战利品修改开启需要时间免得被轻松白嫖,请问应该怎么改
<append xpath=”/lootcontainers/lootcontainer[@name='reinforcedChestT1']”>open_time=”5.25″</append>
[教程]XPath指南 - 攻略教程 - 七日杀中文网 (7risha.com)
看这里,有增加和减少属性的语句用法
看了一下你这个是set xpath的写法,我看了文件是一整条黏在一起 我试了一下insertAfter和append插入和附加代码都没办法插入你的open_time=”5.25″,我自己能想到的是两个办法。一个就是
<remove xpath="/loot//lootcontainer[@name='reinforcedChestT1']"/>删除这一条。然后自己再
<append xpath ="/loot"><!--新建属性-->
<lootcontainer name="reinforcedChestT1" count="1" size="8,9" sound_open="UseActions/chest_tier1_open" sound_close="UseActions/chest_tier1_close" loot_quality_template="qualPlus1Template" ignore_loot_abundance="true" open_time="5.25" />
<item group="groupReinforcedChestT1"/>
</lootcontainer>
</append>
第二个方法就是使用XPath和Python中的ElementTree库来修改XML文件
import xml.etree.ElementTree as ET tree = ET.parse('loot.xml') root = tree.getroot() lootcontainer = root.find(".//lootcontainer[@name='reinforcedChestT1']") lootcontainer.set('open_time', '5.25') tree.write('loot.xml')
这是我能想到的两个方法了,期待其他大佬的回答
核危机军队IP8.138.139.11端口26900
弄好了,分享一下方法
<setattribute xpath="/lootcontainers/lootcontainer[@name='reinforcedChestT1']" name="open_time">5.25</setattribute>
<setattribute xpath="/lootcontainers/lootcontainer[@name='reinforcedChestT2']" name="open_time">5.25</setattribute>
<setattribute xpath="/lootcontainers/lootcontainer[@name='reinforcedChestT3']" name="open_time">5.25</setattribute>
<setattribute xpath="/lootcontainers/lootcontainer[@name='hardenedChestT4']" name="open_time">5.25</setattribute>
<setattribute xpath="/lootcontainers/lootcontainer[@name='hardenedChestT5']" name="open_time">5.25</setattribute>
擅长做一些简单的mod。