Python2.7 a代码如下,只是个简单的例子,实际开发自由发挥
import xml.dom.minidom as xmldom
domTree = xmldom.parse('AndroidManifest.xml')
root = domTree.documentElement
application = root.getElementsByTagName('application')
for app in application:
activity = app.getElementsByTagName('activity')
for ac in activity:
activityValue = ac.getAttribute('android:screenOrientation')
if activityValue == "":
ac.setAttribute('android:screenOrientation', 'portrait')
print(ac.getAttribute('android:screenOrientation'))
else:
print '有'
try:
f = open("book_store.xml", "w")
f.write(domTree.toprettyxml(indent="", newl="", encoding="utf-8"))
f.close()
except Exception as err:
print('错误信息:{0}'.format(err))
复制代码
转载于:https://juejin.im/post/5aeb09716fb9a07acd4d930b