This reference is for Processing 2.0+. 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.

Name

parseXML()

Examples
String data = "<mammals><animal>Goat</animal></mammals>";

void setup() {
  XML xml = parseXML(data);
  if (xml == null) {
    println("XML could not be parsed.");
  } else {
    XML firstChild = xml.getChild("animal");
    println(firstChild.getContent());
  }
}

// Sketch prints:
// Goat
Description Takes a String, parses its contents, and returns an XML object. If the String does not contain XML data or cannot be parsed, a null value is returned.

parseXML() is most useful when pulling data dynamically, such as from third-party APIs. Normally, API results would be saved to a String, and then can be converted to a structured XML object using parseXML(). Be sure to check if null is returned before performing operations on the new XML object, in case the String content could not be parsed.

If your data already exists as an XML file in the data folder, it is simpler to use loadXML().
Syntax
parseXML(xmlString)
parseXML(xmlString, options)
ReturnsXML
RelatedXML
loadXML()
saveXML()
Updated on May 19, 2014 05:30:00pm PDT

Creative Commons License