Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xmllint/Xpath提取父节点,其中子节点包含来自google购物提要的文本_Xpath_Xmllint_Google Shopping - Fatal编程技术网

xmllint/Xpath提取父节点,其中子节点包含来自google购物提要的文本

xmllint/Xpath提取父节点,其中子节点包含来自google购物提要的文本,xpath,xmllint,google-shopping,Xpath,Xmllint,Google Shopping,我正在尝试提取包含文本值为“2020-2021”的g:custom_label_0的所有“item”节点 到目前为止,我设法找到了包含子g:custom_label_0的所有节点,但我没有设法按字段的文本值进行过滤 以下是示例XML: <item> <description>[...]</description> <g:availability>in stock</g:availability>

我正在尝试提取包含文本值为“2020-2021”的g:custom_label_0的所有“item”节点 到目前为止,我设法找到了包含子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>
   ...
我尝试通过方括号等添加文本过滤器。但我感觉自定义标签0周围的引号可能会引起麻烦。在引号中添加更多的过滤器会被接受(没有错误),但我无法在引号中添加更多的引号来过滤字符串

工作正常,不会抛出错误:

xmllint --xpath '//item["g:custom_label_0[text()]"]' myfile.xml 

如果我现在想过滤文本,我需要再次使用引号。逃脱它们会破坏密码。如果已经使用了两种引号,我如何进一步过滤文本“2020-2021”;
g:custom\u label\u 0
周围的引号引起了麻烦。这使得它成为一个字符串,并且始终为true,因此它将返回所有
元素

g:
是名称空间前缀。要将命名空间绑定到xmllint中的前缀,必须在shell模式下使用它(参见示例)

另一种方法是测试元素名称以选择
g:custom\u label\u 0
元素,然后测试该元素的值以查看其是否为
2020-2021

例如

xmllint--xpath'//item[*[name()=“g:custom_label_0”][.=“2020-2021”]]”myfile.xml
xmllint --xpath '//item["g:custom_label_0[text()]"]' myfile.xml