XPath获取最大ID [英] XPath to get the maximum ID
问题描述
XML 源代码:
<schools>
<school>
<name>School A</name>
<student>
<name>Student A</name>
<id>12345</id>
</student>
<student>
<name>Student B</name>
<id>45678</id>
</student>
</school>
<school>
<name>School C</name>
<student>
<name>Student C</name>
<id>91178</id>
</student>
<student>
<name>Student D</name>
<id>99999</id>
</student>
</school>
</schools>
我仍然是 XPath 的初学者.我想获得总体 ID 最高的学生(示例中为 99999),而不是来自每所学校.我无法更改我的 python 代码,即
I am still a beginner to XPath. I want to get the student with the overall highest ID (so 99999 in the example), not from each school. I can't change my python code which is
tree.xpath(" ... ")
我只能修改xpath.我试过 "//student[not(../student/id > id)]
但这给了我来自各自学校的最高 ID 学生.我想要的是整体最高 ID.应该如何我修改了我的 xpath?
I can only modify the xpath. I have tried "//student[not(../student/id > id)]
but this gives me highest id students from respective schools. What I want is the overall highest ID. How should I modify my xpath?
如何从学校水平开始写作?我的意思是如果我想要最高ID"学生退出的学校名称怎么办?
Edited : How do I write starting from the school level? I mean what if I want the school name which "highest ID" student exits?
推荐答案
关于:
//student[not(../../school/student/id > id)]
或者,更简单:
//student[not(//student/id > id)]
要获得具有最高学生 ID 的 <school/>
元素,我相信这会起作用:
To get the <school/>
element with the highest student ID, I believe this will work:
//school[student[not(//student/id > id)]]
这篇关于XPath获取最大ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!