如何使用 bash 脚本编辑 XML? [英] how to edit XML using bash script?

查看:27
本文介绍了如何使用 bash 脚本编辑 XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<root>
<tag>1</tag>
<tag1>2</tag1>
</root>

需要从 bash 更改值 1 和 2

Need to change values 1 and 2 from bash

推荐答案

tag的值改为2tag13 的值,使用 XMLStarlet:

To change tag's value to 2 and tag1's value to 3, using XMLStarlet:

xmlstarlet ed 
  -u '/root/tag' -v 2 
  -u '/root/tag1' -v 3 
  <old.xml >new.xml

<小时>

使用您的示例输入:


Using your sample input:

xmlstarlet ed 
  -u '/root/tag' -v 2 
  -u '/root/tag1' -v 3 
  <<<'<root><tag>1</tag><tag1>2</tag1></root>'

...作为输出发出:

<?xml version="1.0"?>
<root>
  <tag>2</tag>
  <tag1>3</tag1>
</root>

这篇关于如何使用 bash 脚本编辑 XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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