Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minidom getElementById not working

Minidom's getElementById function is returning None for any entry I pass to it.

For example, this code:

l = minidom.parseString('<node id="node">Node</node>')
print(l.getElementById("node"))

Prints "None" on my computer.

I must be doing something here wrong but I can't figure it out!

I'm running Python 3.3.2 if that helps.

like image 960
James Williams Avatar asked Jul 09 '14 12:07

James Williams


1 Answers

If you want to get elements with name="node"

l.getElementsByTagName("node")

If you want to get elements with attribute having an attribute "id" with value "node", use xpath:

import xpath
xpath.find("//*['id=node']",l) #search for all elements with an attribute id="node"
like image 171
Ankush Shah Avatar answered Sep 29 '22 15:09

Ankush Shah