使用 XMLStarlet(图像注释)将值连接到现有的 xml 属性 [英] Concatenate a value to an existing xml attribute using XMLStarlet (Image Annotation)

查看:27
本文介绍了使用 XMLStarlet(图像注释)将值连接到现有的 xml 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 xml 注释图像.我正在使用 xmlstarlet 和 unix bash 命令,但是当我尝试将值附加到现有 xml 属性值时遇到了一些问题.例如,我有 a 并且我想让它 a.jpg(即连接 '.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).

我使用了以下代码,但它完全覆盖了值(即 .jpg.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆