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