XPath来获得最高的ID元素 [英] XPath to get the element with the highest ID

查看:149
本文介绍了XPath来获得最高的ID元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XML源:

 <文件>
    <文件>
        < ID>第3版; / ID>
    < /文件>
    <文件>
        < ID> 7< / ID>
    < /文件>
    <文件>
        < ID> 1< / ID>
    < /文件>
< /文件>
 

我需要在的文档元素,在它的id元素的最高值(让<文件>< ID> 7< / ID>< /文件&GT ; 中的例子)。我不能改变C#code,它是 XMLDocument.SelectSingleNode(...),我只能修改使用的XPath。

有什么样文件/文件[ID = MAX(ID)] 或如按id降序排列得到它?

解决方案

 文件/文件[不(../文件/ ID> ID)]
 

XML Source:

<documents>
    <document>
        <id>3</id>
    </document>
    <document>
        <id>7</id>
    </document>
    <document>
        <id>1</id>
    </document>
</documents>

I need the document-element with the highest value in its id-element (so <document><id>7</id></document> in the example). I can't change the C# code, it is XMLDocument.SelectSingleNode(...), I only can modify the XPath used.

Is there something like documents/document[id=max(id)] or like order by id descending to get it?

解决方案

documents/document[not(../document/id > id)]

这篇关于XPath来获得最高的ID元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆