开发者

BASH - How to replace only one tag in an XML, when duplicates appear?

Here is how my xml file looks like:

    <modelVersion>4.0.0</modelVersion>
    <version>5.1.3-SNAPSHOT</version>

<parent>
    <artifactId>xxx&l开发者_C百科t;/artifactId>
    <groupId>group</groupId>
    <version>5.1.3-SNAPSHOT</version>
</parent>

<artifactId>yyy</artifactId>
<packaging>pom</packaging>
<name>artifact name</name>

<modules>           
    <module>m1</module>
    <module>m2</module>
    <module>m3</module>
</modules>

I want to delete the "-SNAPSHOT" string ONLY from the tag within <parent>.

How do I do that?


This is past the capabilities of simple line-based approaches. You might use sed magic with line selection operators or do perl.

An example in sed would be (but just for educational purposes! Don't try this at home! This script is pretty unstable towards changes in the XML):

/<parent>/,/<.parent>/s/-SNAPSHOT//

However, XSLT and xsltproc is definitely the preferred solution for such heavy XML-processing duties.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜