xmllint 根据 xml 文档中的标签名称搜索标签值

xmllint Search value of a tag based on tag name in xml document

我正在尝试使用 xmllint 从 xml 文档中提取一个值。但是 xml 的结构如下。

    <configuration> 
    <property>
    <name>hive.exec.reducers.max</name>
    <value>999</value>

    <description>max number of reducers will be used. If the one
        specified in the configuration parameter mapred.reduce.tasks is
        negative, hive will use this one as the max number of reducers when
        automatically determine number of reducers.</description>


      </property>

  <property>

    <name>hive.cli.print.header</name>
    <value>false</value>

    <description>Whether to print the names of the columns in query output.</description>


  </property>
  <property>

<name>hive.cli.print.current.db</name>

    <value>false</value>

    <description>Whether to include the current database in the hive prompt.</description>


  </property>
</configuration>

比方说,我想提取 hive.cli.print.current.db 的值,输出应该是 "false"。 xmllint 如何用于从 xml 文档中的给定名称标签中提取值。

以下 xpath 查询应该有效。

xmllint --xpath "//property[name[text()='hive.cli.print.current.db']]/value/text()" file.xml

翻译:

查找 属性 包含具有给定文本的子节点(名称)和包含在另一个(值)子节点中的文本的 return 元素。