#! /usr/bin/env python
import sys
import os
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
# -*- coding:utf-8 -*-
#list
tree = ET.parse("test.xml")
root = tree.getroot()
for i in root:
print i.text #i is child of root . print the content of i
i.set('lalala',"blahblah") #add an attribution to i
print i.attrib #print all attribution
网友评论