I built a Python script (with minidom) to manipulate the layout of an Android app, which is defined in an XML file. Widgets are elements in the android namespace, for example:
<TextView android:id="@+id/myId" android:text="..." />
Note the android:id attribute and its required format @+id/.... I didn’t find a way to pick that element with getElementById(). Maybe it’s because I don’t know minidom, but more likely it’s because I don’t understand XML namespaces deeply.
I remember that id is an attribute to uniquely identify an element in a tree. I never saw a namespaced ID, so my guess is that android:id isn’t really an ID, but just an attribute which happens to be called id in the android namespace. In this case there’s no way to getElementById, because it works with XML id’s. Currently I traverse the dom and check the android:id attribute to get my target element, but this technique is obviously less flexible than getElementById directly
Disclaimer: I tagged this with xslt because I think that xslt people can know the answer since they are used to working with XML and namespaces
OK – I found something else that may be of help to you. Apparently it depends on what has been listed of being of type “ID”. Where is that defin ed and can you influence it? I don’t know 🙁 But check How to set element's id in Python's xml.dom.minidom?
See extract below from http://www.w3.org/TR/DOM-Level-2-Core/core.html
getElementById introduced in DOM Level 2
Returns the Element whose ID is given by elementId. If no such element exists, returns null. Behavior is not defined if more than one element has this ID.
Note: The DOM implementation must have information that says which attributes are of type ID. Attributes with the name “ID” are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null.