I recursively pass through all the nodes in an XML:
def verify_elements_children(root):
if root.childNodes:
for node in root.childNodes:
if node.nodeType == node.ELEMENT_NODE:
if node.tagName in config_elements_children[node.parentNode.tagName]:
# print node.toxml()
verify_elements_children(node)
But I don't know how to get all the attributes names of the selected the selected node?
You can simply access the attributes property, which is a NamedNodeMap, on which you can call items to get the string keys and values:
import xml.dom.minidom
n = xml.dom.minidom.parseString('<n a="1" b="2" />').documentElement
attrs = dict(n.attributes.items())
assert attrs == {'a': '1', 'b': '2'}
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