使用XMLStarlet(图像注释)将值连接到现有xml属性 [英] Concatenate a value to an existing xml attribute using XMLStarlet (Image Annotation)
问题描述
我正在使用xml注释图像.我正在使用xmlstarlet和unix bash命令,但是在尝试将值附加到现有xml属性值时遇到了一些问题.例如,我有<filename>a</filename>
,我想将其设置为<filename>a.jpg</filename>
(即,将".jpg"连接到现有值).
I am working on annotating images using xml. I am using xmlstarlet and unix bash commands but I am facing some issues when I try to append a value to an existing xml attribute value. For example, I have <filename>a</filename>
and I want to make it <filename>a.jpg</filename>
(i.e. concatenate '.jpg' to the existing value).
我使用了以下代码,但是它完全覆盖了值(即<filename>.jpg</filename>
.
I used the following piece of code but it totally overwrites the value (i.e. <filename>.jpg</filename>
.
脚本:
for name in *.xml; do xmlstarlet ed --inplace -u '/annotation/filename' -v .jpg "$name"; done
推荐答案
xmlstarlet
解决方案:
xmlstarlet
solution:
xmlstarlet ed -L -u '//annotation/filename' -x 'concat(., ".jpg")' input.xml
快速指南:xmlstarlet ed --help
这篇关于使用XMLStarlet(图像注释)将值连接到现有xml属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!