xml




minidom

from xml.dom import minidom # test.xml を開く doc = minidom.parse("d:/test.xml") # <test> 要素を取得 e = doc.getElementsByTagName("test")[0] # test name= の値を取得 print(e.getAttribute("name")) # attribute をセット e.setAttribute("name", "test") print(e.getAttribute("name")) # XML 文書の全ての構成要素は Node のサブクラス print ( e.parentNode.localName ); # Node をつくり、子供に追加 n = doc.createElement( "newnode" ); n.setAttribute( "key", "value" ); e.appendChild( n ); # 保存 fp=open("d:/out.xml","w") doc.writexml(fp) fp.close()