Detect empty XML root element

Cisecoleviriaa

New Member
I am reading in a bunch of XML files. If the file only contains an empty root element like:\[code\]<?xml version="1.0" encoding="UTF-8"?><root />\[/code\]I want to skip over it. Currently I do:\[code\]import xml.etree.cElementTree as ET xml = ET.parse(filename)if not [el for el in xml.getroot()]: # skip\[/code\]Is there a better way to handle this case?
 
Back
Top