【发布时间】:2021-08-10 13:43:27
【问题描述】:
我有一个包含大量 XML 代码的文件,我想用某个值修改该文件的一部分。
例子:
假设我有很多名为 target 的标签,我想搜索某个名称来进行修改。
<target name="forest US" description="have more species" >
<modification.start.yes/>
<modif.fr.ss type="Animals" color="brown" outputFile="New_type.csv" />
<modification.end.yes/>
</target>
我想要做的是在我的 XML 文件中搜索名称为 forest US 的标签,将类型从 Animals 更改为 Plants em> 例如 以及从 New_type.csv 到 Old_type.csv 的输出文件。
我尝试使用这个 sed 命令:
(一般的命令)
sed 's#<target name="forest US" description="have more species">.*#<target name="forest US" description="have more species">SOMETHING</target>#' file.xml
我想知道是否有其他方法,因为这个方法不能正常工作。
谢谢!
【问题讨论】:
-
使用 XSLT 转换是一项非常简单的任务。