-1
<?xml version="1.0" encoding="utf-8"?>
<FRUIT>
<APPLE>
<COLOR RED = "TRUE"/>
<TASTE SWEET = "TRUE" />
</APPLE>
<ORANAGE>
<COLOR ORANGE = "TRUE"/>
<TASTE SWEET = "FALSE" />
</ORANAGE>
</FRUIT>
我需要一個類似於上述元素的XML解析器。 我需要計算子元素的長度,如apple,即COLOR和TASTE應該計算長度。我試過:python中子元素計算的長度
tree = ET.parse("abc.xml")
root = tree.getroot()
for child in root:
print len(root.findall(child.tag))
print child.tag
好吧,你有什麼嘗試過自己? – DeepSpace
樹= ET.parse在根( 「abc.xml」) 根= tree.getroot() 兒童: \t打印LEN(root.findall(child.tag)) \t打印child.tag –