我正在尝试提取所有包含 ag:custom_label_0 且文本值为“2020-2021”的“项目”节点到目前为止,我设法找到包含子 g:custom_label_0 的所有节点,但我无法按文本过滤字段的值。
这是示例 XML:
<item>
<description>[...]</description>
<g:availability>in stock</g:availability>
<g:brand>Barts</g:brand>
<g:condition>new</g:condition>
<g:custom_label_0>2020-2021</g:custom_label_0>
<g:id>108873/10-3</g:id>
<g:image_link>[...]</g:image_link>
<g:price>26.99 EUR</g:price>
<g:sale_price>26.99 EUR</g:sale_price>
<g:shipping>
<g:country>NL</g:country>
<g:price>4.50 EUR</g:price>
</g:shipping>
<g:shipping_weight>7.95</g:shipping_weight>
<link>[....]</link>
</item>
...
有节点包含除 2020-2021 之外的其他值,但我想提取包含此文本的所有完整项目节点。这是我为提取具有可用字段的所有节点所做的。
xmllint --xpath '//item["g:custom_label_0"]' myfile.xml
我尝试通过方括号等添加文本过滤器,但我觉得 custom_label_0 周围的引用可能会造成麻烦。在引号中添加更多过滤器被接受(没有错误),但我将无法在其中添加更多引号来过滤字符串。
确实有效,不会引发错误:
xmllint --xpath '//item["g:custom_label_0[text()]"]' myfile.xml
如果我现在想过滤文本,我需要再次使用引号。转义它们会破坏代码。当两种引号都已使用时,如何进一步过滤文本“2020-2021”?