Loads an XML file to create a p5.XML object.
Extensible Markup Language (XML) is a standard format for sending data between applications. Like HTML, the XML format is based on tags and attributes, as in <time units="s">1234</time>.
The first parameter, path, is always a string with the path to the file. Paths to local files should be relative, as in loadXML('/assets/data.xml'). URLs such as 'https://example.com/data.xml' may be blocked due to browser security. The path parameter can also be defined as a Request object for more advanced usage.
The second parameter, successCallback, is optional. If a function is passed, as in loadXML('/assets/data.xml', handleData), then the handleData() function will be called once the data loads. The p5.XML object created from the data will be passed to handleData() as its only argument. The return value of the handleData() function will be used as the final return value of loadXML('/assets/data.xml', handleData).
The third parameter, failureCallback, is also optional. If a function is passed, as in loadXML('/assets/data.xml', handleData, handleFailure), then the handleFailure() function will be called if an error occurs while loading. The Error object will be passed to handleFailure() as its only argument. The return value of the handleFailure() function will be used as the final return value of loadXML('/assets/data.xml', handleData, handleFailure).
This function returns a Promise and should be used in an async setup with await. See the examples for the usage syntax.
Examples
Syntax
loadXML(path, [successCallback], [errorCallback])
Parameters
Error event object.