我有一个像这样的xml文件:
<carSchema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="carSchema.xsd">
<car>
<License>23</License>
<year>2010</year>
<model>a</model>
<manufacturer>hyundai</manufacturer>
</car>
<car>
<License>24</License>
<year>2002</year>
<model>b</model>
<manufacturer>hyundai</manufacturer>
</car>
<car>
<License>25</License>
<year>2005</year>
<model>c</model>
<manufacturer>hyundai</manufacturer>
</car>
<car>
<License>26</License>
<year>2004</year>
<model>d</model>
</car>
<car>
<License>27</License>
<year>2016</year>
<model>f</model>
<manufacturer>hyundai</manufacturer>
</car>
我想在Xquery找到有关最新车的信息。我写了这个查询,返回最新车年。
xquery version "1.0";
max(
for $x in doc("car.xml")/carSchema/car
order by $x/year descending
return $x/year)
我如何返回有关该车的所有信息(许可证,型号,制造商)?
答案 0 :(得分:1)
您可以使用
(for $car in doc("car.xml")/carSchema/car
order by $car/year descending
return $car)[1]/*
查找具有最新年份或
的元素的所有子元素(for $car in doc("car.xml")/carSchema/car
order by $car/year descending
return $car)[1]
用最新的一年找到元素本身。