Reference for Processing version 1.2. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.



// The following short XML file called "sites.xml" is parsed 
// in the code below. It must be in the project's "data" directory
// <?xml version="1.0"?>
// <websites>
//   <site id="0" url="">Processing</site>
//   <site id="1" url="">Processing Mobile</site>
// </websites>

XMLElement xml;

void setup() {
  size(200, 200);
  xml = new XMLElement(this, "sites.xml");
  int numSites = xml.getChildCount();
  for (int i = 0; i < numSites; i++) {
    XMLElement kid = xml.getChild(i);
    int id = kid.getIntAttribute("id"); 
    String url = kid.getStringAttribute("url"); 
    String site = kid.getContent();
    println(id + " : " + url + " : " + site);    
Description XMLElement is a representation of an XML object. The object is able to parse XML code. The methods described here are the most basic. More are documented in the Developer's Reference.

The encoding parameter inside XML files is ignored, only UTF-8 (or plain ASCII) are parsed properly.
getChildCount() Returns the number of children for the element.
getChild() Returns a single child.
getChildren() Returns all of the children as an XMLElement array.
getContent() Returns the content of an element
getIntAttribute() Returns an integer attribute of the element.
getFloatAttribute() Returns a float attribute of the element.
getStringAttribute() Returns a String attribute of the element.
getName() Returns the name of the element.
XML(parent, file)
parent PApplet: typically use "this"
file String: name of the XML file to load
Usage Web & Application
Updated on June 14, 2010 12:05:29pm EDT

Creative Commons License