xmlstarlet update value nothing happens

孤街浪徒 提交于 2019-12-01 18:58:33

问题


I have an xml file

<?xml version="1.0"?>
<preferences>
    <!--General options-->
    <options>
            <dbHost>localhost</dbHost>
            <dbUser>bwserver</dbUser>
            <dbPass>bwserver</dbPass>
            <dbPort>3306</dbPort>

How can i update the value dbUser?

When I type

xmlstarlet edit --update '/preferences/options/dbUser/'  --value 123 preferences.xml

nothing happens. I only see the file contents in terminal. The xml file was not touched.


回答1:


You have two faults:

  1. Your XPath expression is invalid. Drop the trailing slash so it becomes /preferences/options/dbUser
  2. By default xmlstarlet does not change the input file, instead it outputs the result in stdout. You can either replace the original file with the xmlstarlet output by redirecting the output to your input file (or to any other file) xmlstarlet edit --update '/preferences/options/dbUser' --value 123 preferences.xml > preferences.xml or you can use global option --inplace which replaces the input file with the output (instead of printing it to stdin). The command is xmlstarlet edit --inplace --update '/preferences/options/dbUser' --value 123 preferences.xml

Type xmlstarlet edit --help for more info



来源:https://stackoverflow.com/questions/15108132/xmlstarlet-update-value-nothing-happens

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!