Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath to get the element with the highest ID

Tags:

People also ask

What does /* mean in XPath?

/* selects the root element, regardless of name. ./* or * selects all child elements of the context node, regardless of name.

Is XPath unique for each element?

Unlike ID attributes, every element in a web page has a unique XPath.

What is attribute in XPath?

Definition of XPath attribute. For finding an XPath node in an XML document, use the XPath Attribute expression location path. We can use XPath to generate attribute expressions to locate nodes in an XML document.

What is current node in XPath?

Current node is the node that the XPath processor is looking at when it begins evaluation of a query. In other words, the current node is the first context node that the XPath processor uses when it starts to execute the query. During evaluation of a query, the current node does not change.


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?