[英]XMLStarlet: Undefined namespace prefix for MARC21
對於 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
由於未定義的命名空間前綴導致錯誤消息:
未定義的命名空間前綴 xmlXPathCompiledEval:評估失敗運行時錯誤:帶有參數的元素無法評估變量“選擇”的表達式。 foo.xml 沒有結果
為什么查詢不起作用並傳遞“Hello world”?
您使用了錯誤的前綴(加上一個小錯字):
xmlstarlet sel -N marcxml="http://www.loc.gov/MARC21/slim" -t -v '//marcxml:collection/marcxml:record/marcxml:leader[text()]' -nl foo.xml
或者,更簡單:
xmlstarlet sel -t -v '//*[local-name()="leader"][text()]' -nl foo.xml
輸出:
Hello world
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.