I am parsing the uses-permission tag in an xml file(androidmanifest.xml) mentioned in an android application
I have tried implementing a for loop to make it iterative but i have failed and so am here
Python:
from xml.dom.minidom import parseString
file = open('/root/Desktop/AndroidManifest.xml','r')
data = file.read()
file.close()
dom = parseString(data)
xmlTag = dom.getElementsByTagName('uses-permission')[0].toxml()
print xmlTag
Output:
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
for loop mistake:
for uses-permission in xmlTag:
#print child.tag, child.attrib
print xmlTag.tag
xmlTag = dom.getElementsByTagName('uses-permission')[1].toxml()
xmlTag= dom._get_childNodes
#print xmlTag
Just open your APK and in treeview select "AndroidManifest. xml". It will be readable just like that.
Every app project must have an AndroidManifest. xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.
To find all the permission tags, try iterating over the nodes that dom.getElementsByTagName('uses-permission')
returns instead of accessing only the node at index 0
:
from xml.dom.minidom import parseString
data = ''
with open('/root/Desktop/AndroidManifest.xml','r') as f:
data = f.read()
dom = parseString(data)
nodes = dom.getElementsByTagName('uses-permission')
# Iterate over all the uses-permission nodes
for node in nodes:
print node.toxml()
or if you want just the permission and not the xml, you can replace node.toxml()
with node.getAttribute('android:name')
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With