【发布时间】:2022-12-22 21:05:03
【问题描述】:
我有一堆 Java 应用程序使用的 XML。 XML 文档中有多个“addService”块,但我只对更新 MySQL 连接使用的服务感兴趣。
以下是需要更改密码的 XML 数据示例块。如何使用 BASH 或 XMLStarlet 更改该块中的密码值?
<Call name="addService">
<Arg>
<New class="org.mortbay.jetty.plus.DefaultDataSourceService">
<Set name="Name">DataSourceService</Set>
<Call name="addDataSource">
<Arg>jdbc/MySQL</Arg>
<Arg>
<New class="com.zaxxer.hikari.HikariDataSource">
<Arg>
<New class="com.zaxxer.hikari.HikariConfig">
<Set name="dataSourceClassName">com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource</Set>
<Set name="maximumPoolSize">15</Set>
<Set name="leakDetectionThreshold">10000</Set>
<Call name="addDataSourceProperty">
<Arg>url</Arg>
<Arg>jdbc:mysql://localhost:3306/db?zeroDateTimeBehavior=convertToNull&useSSL=false</Arg>
</Call>
<Call name="addDataSourceProperty">
<Arg>user</Arg>
<Arg>test</Arg>
</Call>
<Call name="addDataSourceProperty">
<Arg>password</Arg>
<Arg>some_password</Arg>
</Call>
</New>
</Arg>
</New>
</Arg>
</Call>
</New>
</Arg>
这是另一个需要更改密码的 XML 块:
<Call name="addService">
<Arg>
<New class="org.mortbay.jetty.plus.DefaultDataSourceService">
<Set name="Name">DataSourceService</Set>
<Call name="addDataSource">
<Arg>jdbc/MySQL</Arg>
<Arg>
<New class="com.jolbox.bonecp.BoneCPDataSource">
<Set name="driverClass">com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource</Set>
<Set name="jdbcUrl">jdbc:mysql://localhost:3306/db?zeroDateTimeBehavior=convertToNull</Set>
<Set name="user">test</Set>
<Set name="password">some_password</Set>
<Set name="acquireIncrement">5</Set>
<Set name="minConnectionsPerPartition">5</Set>
<Set name="maxConnectionsPerPartition">50</Set>
<Set name="idleConnectionTestPeriod">30</Set>
</New>
</Arg>
</Call>
</New>
</Arg>
</Call>
【问题讨论】:
标签: xml bash xmlstarlet