BeautifulSoup
做到這一點:
>>> from bs4 import BeautifulSoup
>>> myxml = # Your posted XML
>>> soup = BeautifulSoup(myxml,'xml')
>>> print soup
<?xml version="1.0" encoding="utf-8"?>
<breakfast_menu>
<food>
<names>Belgian Waffles</names>
<price>$5.95</price>
<calories>650</calories>
</food>
</breakfast_menu>
如果您正在尋找<name></name>
:
>>> for i in soup.findAll('names'):
... i.name = 'name'
...
>>> print soup
<?xml version="1.0" encoding="utf-8"?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<calories>650</calories>
</food>
</breakfast_menu>
[這個答案](http://stackoverflow.com/a/399996/477878)可能會感興趣。 – 2013-04-21 06:03:45
爲什麼你會得到這樣畸形的xml文件?是否有可能修復生成XML的程序? – xwang 2016-06-28 19:44:47