This function takes as input an XML document represented as a string, and returns the document node at the root of an XDM tree representing the parsed document.

parse-xml($arg as xs:string?) ➔ document-node(element(*))





The lexical XML string to be parsed as a document





Links to W3C specifications

XPath 3.1 Functions and Operators

Notes on the Saxon implementation

Available since Saxon 9.3, provided XPath 3.0 is enabled; replaces the extension function saxon:parse which is retained for the time being.

Saxon parses the supplied document using the "source parser" registered with the configuration. It sets a custom ErrorHandler to be notified of parsing errors; this outputs nothing, but instead captures any notified exceptions. If the parsing failure is caught using try/catch, these exceptions are available as the value of $err:value: specifically, $err:value is a sequence of items, each of which is a Java ExternalObject wrapping a SAXParseException, which can be interrogated using reflexive extension functions to obtain details such as the line number of the error.