【发布时间】:2023-03-29 14:44:02
【问题描述】:
xml enter image description here
我需要更改屏幕上标记的版本。
我试试:
with open(PathPom,'r') as f:
tree = ET.parse(f)
root = tree.getroot()
for elem in root.getiterator():
try:
elem.text = elem.text.replace('1.4.1', '5.0.0')
except AttributeError:
pass
tree.write(PathPom,xml_declaration=True, method='xml')
pom中所有1.4.1版本都是replace,文档中所有行以<ns0开头
你知道如何解决吗?
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>cterminal</groupId>
<artifactId>Monitor</artifactId>
<version>1.4.1</version>
<packaging>lba</packaging>
<properties>
<lb.middlewareVersion>1.7.0</lb.middlewareVersion>
</properties>
<build>
<plugins>
<plugin>
<groupId>.maven</groupId>
<artifactId>lba-maven-plugin</artifactId>
<version>${lb.middlewareVersion}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<message>The lba-maven-plugin requires Maven version to be at
least 3.1.1!</message>
<version>[3.1.1,)</version>
</requireMavenVersion>
<dependencyConvergence/>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
-
欢迎来到 SO!请将您的 XML 发布为代码格式的文本(而不是图像),最好简化为仅包含相关元素、目标
version和一些其他元素以演示问题,即 1 或 2 个元素被您的代码替换,而它不应该... -
另一个提示:要格式化你的代码,选择代码块然后点击编辑器顶部的
{}或按住CTRL+K
标签: xml python-2.7 pom.xml