I have the following XML file :
<Configuration .... status="INFO" >
<properties>
<property name="logfile">/var/log/app.log</property>
<property name="log-level">INFO</property>
</properties>
</Configuration>
I'm trying to replace the INFO in the log-level property to DEBUG.
[root]# xmlstarlet edit --update "/Configuration/properties/property[@name='log-level']/@value" --value DEBUG test.xml
<?xml version="1.0"?>
<Configuration status="INFO">
<properties>
<property name="logfile">/var/log/app.log</property2>
<property name="log-level">INFO</property>
</properties>
</Configuration>
The output in stdout is exactly the same as the orig file, nothing is changed.
I tried to search for the XPath to make sure that I used the right one and it worked :
[root]# xmlstarlet sel -t -v "count(Configuration/properties/property[@name='log-level'])" test.xml
1
I tried also to change the @name instead of the @value and it worked.
What am I missing ? Why the output(in stdout) isn't changed ?
xmlstarlet edit --inplace --update "/Configuration/properties/property[@name='log-level']" --value "DEBUG" test.xml
- the/@value
part in your XPath is not necessary. Also add the--inplace
option (or it's shorthand equivalent-L
) to edit the file inplace. If you want to exclude the xml declaration, i.e.<?xml version="1.0"?>
, in the resultant file include the--omit-decl
option (or it's shorthand equivalent-O
) too, for example:xmlstarlet edit --inplace --omit-decl --update "/Configuration/properties/property[@name='log-level']" --value "DEBUG" test.xml
– RobC