我在更新以下xml文件时遇到问题。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config xmlns="http://artifactory.jfrog.org/xsd/2.0.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jfrog.org/xsd/artifactory-v2_0_5.xsd">
<serverName>DGI-Artifactory</serverName>
<offlineMode>false</offlineMode>
<helpLinksEnabled>true</helpLinksEnabled>
<fileUploadMaxSizeMb>2000</fileUploadMaxSizeMb>
<dateFormat>dd-MM-yy HH:mm:ss z</dateFormat>
<addons>
<showAddonsInfo>true</showAddonsInfo>
<showAddonsInfoCookie>1413295590171</showAddonsInfoCookie>
</addons>
<mailServer>
<enabled>true</enabled>
<host>smtp.base.dom</host>
<port>25</port>
<username/>
<password/>
<subjectPrefix>[Artifactory Prod - NPM]</subjectPrefix>
<tls>false</tls>
<ssl>false</ssl>
<artifactoryUrl>https://artifactory.groupxx.net/artifactory</artifactoryUrl>
</mailServer>
<bintrayConfig>
<fileUploadLimit>0</fileUploadLimit>
</bintrayConfig>
<security>
<anonAccessEnabled>true</anonAccessEnabled>
<anonAccessToBuildInfosDisabled>false</anonAccessToBuildInfosDisabled>
<hideUnauthorizedResources>false</hideUnauthorizedResources>
<passwordSettings>
<encryptionPolicy>supported</encryptionPolicy>
<expirationPolicy>
<enabled>false</enabled>
<passwordMaxAge>60</passwordMaxAge>
<notifyByEmail>true</notifyByEmail>
</expirationPolicy>
<resetPolicy>
<enabled>true</enabled>
<maxAttemptsPerAddress>3</maxAttemptsPerAddress>
<timeToBlockInMinutes>60</timeToBlockInMinutes>
</resetPolicy>
</passwordSettings>...
我想将以下值更改为5
<maxAttemptsPerAddress>3</maxAttemptsPerAddress>
在阅读了大量文档后,包括关于stackoverflow的多篇帖子,类似于this
并尝试许多类似的命令和变体:
xmlstarlet ed --inplace -u '/config/security/passwordSettings/expirationPolicy/resetPolicy/maxAttemptsPerAddress' -v 5 test.xml
xmlstarlet ed --inplace -u /config[@xmlns=*][@xmlns:xsi=*][@xsi:schemaLocation=*]/security/passwordSettings/expirationPolicy/resetPolicy/maxAttemptsPerAddress -v 5 test.xml
xmlstarlet ed --inplace -u /config[@xmlns="http://artifactory.jfrog.org/xsd/2.0.5"][@xmlns:xsi=*][@xsi:schemaLocation=*]/security/passwordSettings/expirationPolicy/resetPolicy/maxAttemptsPerAddress -v 5 test.xml
xmlstarlet仍然没有更新所需的值:
我认为这里的主要问题是多个xmlns
配置值,但是到目前为止,我还没有找到解决方案。
答案 0 :(得分:0)
实际上,您需要使用选项-N
定义名称空间,并将其显式地用于每个节点:
xmlstarlet ed -N a="http://artifactory.jfrog.org/xsd/2.0.5" -u /a:config/a:security/a:passwordSettings/a:resetPolicy/a:maxAttemptsPerAddress -v 5 file.xml
此处,命名空间a
设置为http://artifactory.jfrog.org/xsd/2.0.5
,用于查找要更新的xpath的所有节点。