2. Java™ methods as extension functions

A call to a function ns:foo where ns is bound to a namespace of the form java:className is treated as a call of the static method foo of the class with fully-qualified name className. Example:


file:createTempFile('xxe', '.tmp')

Hyphens in method names are removed with the character following the hyphen being upper-cased. Example:

file:create-temp-file('xxe', '.tmp')

is equivalent to:

file:createTempFile('xxe', '.tmp')

A non-static method is treated like a static method with the this object as an additional first argument. Example:

file:delete-on-exit(file:createTempFile('xxe', '.tmp'))

A constructor is treated like a static method named new. Example:



Overloading based on number of parameters is supported; overloading based on parameter types is not. Example, it is possible to invoke:


though both java.net.URL(java.lang.String spec) and java.net.URL(java.net.URL context, java.lang.String spec) exist. It is not possible to invoke:


because both java.io.File(java.lang.String pathname) and java.io.File(java.net.URI uri) exist.

Extension functions can return objects of arbitrary types which can then be passed as arguments to other extension functions.

Types are mapped between XPath and Java™ as follows:

XPath typeJava™ type

On return from an extension function, an object of type com.xmlmind.xml.doc.XNode is also allowed and will be treated as a node-set; also any numeric type is allowed and will be converted to a number.