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))
複製程式碼