How to code XML processing using Processing(Python mode)

Processing.org/reference/loadXML_.html

FILENAME = 'test02.xml'
RECORD, TYPE, VALUE = 'Record', 'type', 'value'

def setup():
    global xml
    xml = loadXML(FILENAME)
    printXMLChildren(xml)
    exit()


def printXMLChildren(xml):
    for child in xml.getChildren(RECORD):
        type = child.getString(TYPE)
        value = child.getFloat(VALUE)
        print type, value

“test02.xml”:

<records>
  <Record type="some stuff" value="74.83" />
  <Record type="another stuff" value="-1e-3" />
</records>
3 Likes