4.2.3 NID Functions

MonetDB/XQuery internally assigns integer Node Identifiers (NIDs) to all XML nodes. These NIDs are tied to node identity and do not change under updates. NIDs are interesting because they provide an uniform way to identify XML nodes, with a very efficient O(1) lookup mechanism (that works in constant time).

pf:nid (element()) as xs:string

The pf:nid() function returns the NID of an element. Though a NID is an integer, it is returned as an xs:string. The NID can be passed as a parameter to the built-in fn:id() function. This standard function allows to lookup nodes by their ID/IDREF values. Since ID/IDREF values cannot be numbers, the fn:id() function can recognize NIDs from normal ID/IDREF attribute values.