1

I am having problems updating the following xml file.

<?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>...

I want to change the following value to 5

<maxAttemptsPerAddress>3</maxAttemptsPerAddress>

After reading lots of documentation, including multiple posts on stackoverflow similar to this

and trying dozens of commands and variations like 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

The xmlstarlet still does not update the desired value: I think the main problem here is multiple xmlns config value, but so far I have not found solution to this.

spaceman117X
  • 223
  • 1
  • 16

1 Answers1

1

You actually need to define the namespace with the option -N, and using it explicitly for each node:

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

Here the namespace a is set to http://artifactory.jfrog.org/xsd/2.0.5 and is used to locate all nodes of the xpath you want to update.

oliv
  • 12,690
  • 25
  • 45