我有 n xml 文件,我想在其中更改三个元素。它是第一、第八和第十<string>
元素。所以我想最简单的方法是这样的(但我愿意接受任何其他建议,谢谢!!):
DOM = xml.dom.minidom
doc = DOM.parse(open(FILENAME))
a = doc.getElementsByTagName('string')
for i in range(len(a)):
if i == 0:
a[i] = new Element with new Text
if i == 7:
a[i] = new Element with new Text
if i == 9:
a[i] = new Element with new Text
那基本上是我的文件:
<plist version="1.0">
<dict>
<key></key>
<string>CHANGE THIS</string>
<string>aaa</string>
<key>aaa</key>
<dict>
<key>aaa</key>
<dict>
<key>aaa</key>
<string>aaa</string>
<key>aaa</key>
<false/>
</dict>
<key>aaa</key>
<dict>
<key>aaa</key>
<string>aaaa.png</string>
<key>aaa</key>
<string>aaa</string>
<key>aaa</key>
<string>aaa</string>
</dict>
</dict>
<key></key>
<true/>
<key></key>
<string></string>
<key></key>
<string>CHANGE THIS</string>
<key></key>
<string></string>
<key></key>
<string>AND CHANGE THIS</string>
<key></key>
<string></string>
<key></key>
<string></string>
<key></key>
<key></key>
<true/>
<key></key>
<string></string>
<key></key>
<key></key>
</dict>
</plist>