Xml 使用XPath选择只包含一个属性的元素
我希望在XML文件中只使用XPath获取只包含一个属性的元素 这是XML文件:Xml 使用XPath选择只包含一个属性的元素,xml,xpath,Xml,Xpath,我希望在XML文件中只使用XPath获取只包含一个属性的元素 这是XML文件: <?xml version="1.0" encoding="UTF-8"?> <livre titre="Mon livre"> <auteurs> <auteur nom="nom1" prenom="prenom1" /> <auteur nom="nom2" prenom="prenom2" /> <
<?xml version="1.0" encoding="UTF-8"?>
<livre titre="Mon livre">
<auteurs>
<auteur nom="nom1" prenom="prenom1" />
<auteur nom="nom2" prenom="prenom2" />
</auteurs>
<sections>
<section titre="Section1">
<chapitre titre="Chapitre1">
<paragraphe>Premier paragraphe</paragraphe>
<paragraphe>Deuxième paragraphe</paragraphe>
</chapitre>
<chapitre titre="Chapitre2">
<paragraphe>Premier paragraphe</paragraphe>
</chapitre>
</section>
<section titre="section2">
<chapitre titre="Chapitre1">
<paragraphe>Premier paragraphe</paragraphe>
<paragraphe>Deuxième paragraphe</paragraphe>
</chapitre>
</section>
</sections>
</livre>
但它不起作用
但是我编写的XPath查询选择包含多个属性的所有元素,我只想选择只包含一个属性的元素
XPath查询的结果应如下所示:
Description: titre="Mon livre"
XPath location: /livre[1]
Start location: 2:1
End location: 20:9
Description: titre="Section1"
XPath location: /livre[1]/sections[1]/section[1]
Start location: 8:5
End location: 16:19
Description: titre="Chapitre1"
XPath location: /livre[1]/sections[1]/section[1]/chapitre[1]
Start location: 9:13
End location: 12:24
Description: titre="Chapitre2"
XPath location: /livre[1]/sections[1]/section[1]/chapitre[2]
Start location: 13:13
End location: 15:24
Description: titre="section2"
XPath location: /livre[1]/sections[1]/section[2]
Start location: 17:9
End location: 18:19
我该怎么做呢?这应该可以:
//*[count(@*)=1]
p、 在美国,我得到了6个项目,对于这些数据,在第2节下有另一个章节
,这应该有效:
//*[count(@*)=1]
p、 在美国,我得到了6个项目,对于这些数据,在第2节下有另一个章节
,这应该有效:
//*[count(@*)=1]
p、 在美国,我得到了6个项目,对于这些数据,在第2节下有另一个章节
,这应该有效:
//*[count(@*)=1]
p、 在美国,我得到了6个项目,对于这些数据,在第2节下还有另一个章节