How to code XML processing using Processing(Python mode)

Hello, I am new to posting in this forum and currently learning Processing (Python mode). I would like to convert the following code from Processing(tested and working) to Python mode but not sure what’s the syntax. Checked Processing.py reference but cannot find commands there for XML processing.
I would like to convert the following, much thanks for your help/tips. Regards, Paul

XML xml;
void setup() {
xml = loadXML(“test02.xml”);
XML[] children = xml.getChildren(“Record”);

for (int i = 0; i < children.length; i++) {
String v_rectype = children[i].getString(“type”);
float v_value = children[i].getFloat(“value”);
println(v_rectype + ", " + v_value);
}
}

1 Like

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

Much thanks GoToLoop!