Home > Software engineering >  xmlstarlet: Selecting element by it's sibling value
xmlstarlet: Selecting element by it's sibling value

Time:11-15

I have this XML file

<?xml version="1.0" encoding="UTF-8">
<Products>
  <Product>
    <DisplayName>DefaultBrowserSettings</DisplayName>
    <IsLoadFromLocalData>false</IsLoadFromLocalData>
    <Message>Installed</Message>
  </Product>
  <Product>
    <DisplayName>IncognitoMode</DisplayName>
    <IsLoadFromLocalData>true</IsLoadFromLocalData>
    <Message>Installed</Message>
  </Product>
</Products>

What I want to do is modify the IsLoadFromLocalData value of an element with DisplayName = "IncognitoMode".

I managed to do this using xmlstarlet, but can't find any documentation for doing that. Does anyone has any idea how this can be done? It's my first time trying to evaluate xmlstarlet.

Im stuck here:

xmlstarlet ed --inplace -u /Products/Product/ -v "false" file.xml

Regards, Nitzan

CodePudding user response:

Try changing it to

xmlstarlet edit  -u "//Product[DisplayName='IncognitoMode']//IsLoadFromLocalData" -v "false"  file.xml

and see if it works.

  • Related