更新时间:2023-11-07 12:34:04
使用-s
(或--subnode
)代替-i
.关于奖励,您不能直接插入带有属性的元素,但是由于每个编辑操作都是按顺序执行的,因此插入一个元素然后添加一个属性:
Use -s
(or --subnode
) instead of -i
. Regarding the bonus, you can't insert an element with an attribute directly but since every edit operation is performed in sequence, to insert an element and then add an attribute:
> xml ed -s /config -t elem -n sub -v "" -i /config/sub -t attr -n class -v com.foo test.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<sub class="com.foo"></sub></config>