Reputation: 23
I'm new to python and now I'm trying use python to read 2D digital coordinates from an xml which is get from andriod application. Part of the xml file should be like the following code(in the orginal file I have lots of such node):
<node bounds="[956,63][1080,210]" selected="false" password="false" long-clickable="true" scrollable="false" focused="false" focusable="true" enabled="true" clickable="true" checked="false" checkable="false" content-desc="search" package="com.android.settings" class="android.widget.Button" resource-id="" text="" index="0"/> </node>
and what I need is try to get every node bounds(the pair of 2D coordinates) from xml file, how to do that in Python?
Upvotes: 0
Views: 653
Reputation: 5496
You can use the xml.dom
library in Python to fulfill your task:
from xml.dom import minidom
nodes = minidom.parse("mydoc.xml").getElementsByTagName("node")
for node in nodes:
print(node.getAttribute("bounds"))
XML File Content I used:
<nodes>
<node bounds="[956,63][1080,210]" selected="false" password="false" long-clickable="true" scrollable="false" focused="false" focusable="true" enabled="true" clickable="true" checked="false" checkable="false" content-desc="search" package="com.android.settings" class="android.widget.Button" resource-id="" text="" index="0"></node>
</nodes>
Upvotes: 1