Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 检测空的XML根元素_Python_Xml_Elementtree - Fatal编程技术网

Python 检测空的XML根元素

Python 检测空的XML根元素,python,xml,elementtree,Python,Xml,Elementtree,我正在读一堆XML文件。如果文件仅包含空的根元素,如: <?xml version="1.0" encoding="UTF-8"?> <root /> 有更好的方法来处理这种情况吗?使用DOM方法ElementTree提供给您: if not xml.getroot().getchildren(): # skip if not xml.getroot().getchildren(): # skip

我正在读一堆XML文件。如果文件仅包含空的根元素,如:

<?xml version="1.0" encoding="UTF-8"?>
<root />

有更好的方法来处理这种情况吗?

使用DOM方法
ElementTree
提供给您:

if not xml.getroot().getchildren(): 
    # skip
if not xml.getroot().getchildren(): 
    # skip