I’m working with python xml.dom. I’m looking for a particular method that takes in a node and string and returns the xml node that is is named string. I can’t find it in the documentation
I’m thinking it would work something like this
nodeObject =parent.FUNCTION('childtoFind')
where the nodeObject is under the parent
Or barring the existence of such a method, is there a way I can make the string a node object?
You are looking for the
.getElementsByTagname()function:It returns a list; if you need only one node, use indexing:
You really want to use the ElementTree API instead, it’s easier to use. Even the
minidomdocumentation makes this recommendation:The ElementTree API has a
.find()function that let’s you find the first matching descendant: