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

标签 xml xmllint

我正在尝试使用 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

翻译:

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

关于xmllint 根据 xml 文档中的标签名称搜索标签值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31127511/

相关文章:

xml - 如何在 xmllint 中允许非绝对 URI?

c# - 带条件的文件解析,显示在屏幕上

java - 将节点添加到节点 XML dom4j

Python SVG 解析器

java - 如何从 hibernate 映射文件生成 Jaxb-XML-Beans?

sql-server - Azure XML 支持

xpath - xmllint未知选项 '--xpath'

xml - native shell 命令集用于从 XML 中提取节点值

xml - 从 shell 向 XML 文档的默认 namespace 的标签添加 namespace 前缀

XMLSchema : Is it possible to calculate how valid an invalid document is (eg. 作为百分比)?