Transforming an XML Document Using _Document Methods,,import sysfr
文章由Byrx.net分享于2019-03-23 06:03:41
Transforming an XML Document Using _Document Methods,,import sysfr
import sysfrom xml.dom.ext import PrettyPrintfrom xml.dom import minidomdoc = minidom.parse(open(sys.argv[1]))for n in doc.getElementsByTagName('ingredients'): n.tagName = 'ingredientlist'for n in doc.getElementsByTagName('item'): n.tagName = 'ingredient' attr = n.getAttribute('num') n.setAttribute('quantity',attr) n.removeAttribute('num')PrettyPrint(doc)
评论关闭