对于XML文件foo.xml
<?xml version="1.0" encoding="UTF-8" ?>
<record><header><identifier>oai:tib.eu:TIBKAT:010000011</identifier><datestamp>2020-10-12</datestamp><setSpec>tibkat</setSpec></header><metadata><marcxml:collection xmlns:marcxml="http://www.loc.gov/MARC21/slim">
<marcxml:record>
<marcxml:leader>Hello world</marcxml:leader>
</marcxml:record>
</marcxml:collection>
</metadata></record>
XMLStarlet查询
xmlstarlet sel -N xmlns="http://www.loc.gov/MARC21/slim" -t -v '//_:collection/_:record/_:leader[text()]' -nl foo.xml
由于未定义的命名空间前缀,导致出现错误消息:
Undefined namespace prefix xmlXPathCompiledEval: evaluation failed runtime error: element with-param Failed to evaluate the expression of variable 'select'. no result for foo.xml
为什么查询无法工作并提供“Hello world”?