Name

loadXML()

Examples
# The following short XML file called "mammals.xml" is parsed
# in the code below. It must be in the project's "data" folder.
#
# <?xml version="1.0"?>
# <mammals>
#     <animal id="0"species="Capra hircus">Goat</animal>
#     <animal id="1"species="Panthera pardus">Leopard</animal>
#     <animal id="2"species="Equus zebra">Zebra</animal>
# </mammals>
xml = loadXML("mammals.xml")
children = xml.getChildren("animal")
for i in range(len(children)):
		id = children[i].getInt("id")
		coloring = children[i].getString("species")
		name = children[i].getContent()
		print("%i, %s, %s" % (id, coloring, name))
# Sketch prints:
# 0, Capra hircus, Goat
# 1, Panthera pardus, Leopard
# 2, Equus zebra, Zebra
Description Reads the contents of a file or URL and creates an XML object with its values. If a file is specified, it must be located in the sketch's "data" folder. The filename parameter can also be a URL to a file found online.

All files loaded and saved by the Processing API use UTF-8 encoding. If you need to load an XML file that's not in UTF-8 format, see the developer's reference for the XML object.
Syntax
loadXML(filename)
Parameters
filenameString: name of a file in the data folder or a URL.
Related XML
parseXML()
saveXML()
loadBytes()
loadStrings()
loadTable()

Updated on Mon Sep 21 15:53:25 2020.

If you see any errors or have comments, please let us know.