代码之家  ›  专栏  ›  技术社区  ›  spaceman117X

xmlstarlet不更新内容

  •  0
  • spaceman117X  · 技术社区  · 6 年前

    更新以下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

    1 回复  |  直到 6 年前
        1
  •  0
  •   oliv    6 年前

    实际上,您需要使用以下选项定义名称空间 -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的所有节点。