xmlstarlet更新值没有任何反应 [英] xmlstarlet update value nothing happens

查看:156
本文介绍了xmlstarlet更新值没有任何反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有xml文件

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

我如何更新值DBUSER?

How can i update value dbUser?

当我键入
xmlstarlet编辑--update'/ preferences /选项/ DBUSER /'--value 123 preferences.xml
什么也没有发生,我只看到在终端文件的内容。也xml文件并没有被感动。

When i type xmlstarlet edit --update '/preferences/options/dbUser/' --value 123 preferences.xml nothing happens, i only see file contents in terminal. And also xml file was not touched.

推荐答案

您有两个缺点:


  1. 您的XPath的前pression无效。降斜线,这样就变成 / preferences /选项/ DBUSER

  2. 默认xmlstarlet不改变输入文件,而不是其输出的结果中标准输出。您可以通过输出重定向到输入文件替换为xmlstarlet输出原始文件(或任何其他文件) xmlstarlet编辑--update'/ preferences /选项/ DBUSER' - 价值123 preferences.xml&GT; preferences.xml ,也可以使用全局选项 - 就地与输出替换输入文件(而不是将它打印到标准输入)。该命令是 xmlstarlet编辑--inplace --update'/ preferences /选项/ DBUSER'--value 123 preferences.xml

  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

键入 xmlstarlet编辑--help 了解更多信息。

这篇关于xmlstarlet更新值没有任何反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆