Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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

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
Xml xpath where子句_Xml_Xpath - Fatal编程技术网

Xml xpath where子句

Xml xpath where子句,xml,xpath,Xml,Xpath,我正在尝试在以下xml文件上构建xpath查询: <recordGroup> <records> <year>1985</year> <album> <name> album1 </name> <artist>artist1 </artist> <label>

我正在尝试在以下xml文件上构建xpath查询:

<recordGroup>
    <records>
        <year>1985</year>   
        <album>
            <name> album1 </name>
            <artist>artist1 </artist>
            <label> labelA</label>
        </album>    
        <album>
            <name>album2 </name>
            <artist>artist2 </artist>
            <label> labelB</label>
        </album>    
    </records>      
    <records>
        <year>1986</year>   
        <album>
            <name>album3 </name>
            <artist> artist1 </artist>
            <label>labelC</label>
        </album>    
        <album>
            <name>album4 </name>
            <artist>artist2</artist>
            <label> labelA</label>
        </album>    
    </records>

</recordGroup>

1985
专辑1
艺人1
拉贝拉
专辑2
艺人2
拉贝尔
1986
专辑3
艺人1
labelC
专辑4
艺人2
拉贝拉
我想检索以下查询:选择所有记录(艺术家、姓名和年份),其中label='LabelA'

XML结构可能不适合显示此数据,但我从另一个软件获取此流,因此无法更改它

有什么建议吗?

试试这个:

var=doc(/recordGroup/records[album[@label=“LabelA”]])


这将带回完整的
记录
,其中包含标签为labelA的唱片集


你也可以使用

//records[album/label='labelA']/*[self::year or self::album[label='labelA']]

这将只返回
年份
和与标签

匹配的完整
专辑
,我想出了一个非常糟糕的解决方案,我不会使用,因为您的解决方案看起来比我的更有效。非常感谢你!
//records[album/label='labelA']/*[self::year or self::album[label='labelA']]