<p>你的问题可能不完整,但至少这里是答案的开始</p>
<p>如果可以使用独立工具<code>xmlstarlet</code>,请尝试以下操作:</p>
<pre class="lang-sh prettyprint-override"><code>xmlstarlet sel -N m=http://maven.apache.or '//m:version' -n /tmp/pom.xml
</code></pre>
<p>输出:</p>
<pre class="lang-xml prettyprint-override"><code>1.1.0.0
2.20.0.0-SNAPSHOT
</code></pre>
<p>然后修改,</p>
<pre class="lang-sh prettyprint-override"><code>xmlstarlet ed -N m=http://maven.apache.org/POM/4.0.0 -u '//m:version' -v 1.2.3.4 /tmp/pom.xml
</code></pre>
<p>输出:</p>
<pre class="lang-xml prettyprint-override"><code><?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.test.proj</groupId>
<artifactId>proj-core</artifactId>
<version>1.2.3.4</version>
</parent>
<groupId>com.test.child</groupId>
<artifactId>sub-module</artifactId>
<version>1.2.3.4</version>
<packaging>pom</packaging>
<name>test</name>
<description>test suite</description>
</project>
</code></pre>
<p>来源/灵感:<a href="https://unix.stackexchange.com/questions/398157/search-replace-in-xml-file-with-sed-or-awk">https://unix.stackexchange.com/questions/398157/search-replace-in-xml-file-with-sed-or-awk</a>和<a href="http://xmlstar.sourceforge.net/doc/UG/ch04s01.html" rel="nofollow noreferrer">XML Starlet manual</a></p>
<p>如果要在Python中执行此操作,请参见例如<a href="https://stackoverflow.com/questions/6523886/find-and-replace-values-in-xml-using-python">Find and Replace Values in XML using Python</a>
(但请认真考虑迁移到Python 3!)</p>