I have the following xml extracted from another xml file.
<notifications>
<notification name="ccmSmtp" oid="1.3.6.1" status="current">
<objects>
<object module="callhome" name="ccmSmtp" />
</objects>
<description>This is a description</description>
</notification>
<notification name="ccmAlertGroup" oid="1.3.6.1" status="current">
<objects>
<object module="callhome" name="callHome" />
</objects>
<description>This is a description</description>
</notification>
<notification name="ccmAlert" oid="1.3.6.1" status="current">
<objects>
<object module="callhome" name="callHome" />
</objects>
<description>This is a description</description>
</notification>
<notification name="ccmSmtp" oid="1.3.6.1" status="current">
<objects></objects>
<description>This is a description</description>
</notification>
</notifications>
I'm using the following Python code.
from xml.dom import minidom
xmldoc = minidom.parse('example.xml')
grammarNode = xmldoc.childNodes[2]
notificationsNode = grammarNode.childNodes[9]
print notificationsNode.toxml()
This python code gives the output of the xml which i have given above.
I tried the following to get the attribute values
notificationlist = xmldoc.getElementsByTagName('notification')
print notificationlist[0].toxml()
notification1 = notificationlist[0]
key = notification1.attributes.keys()
Using this I'm able to get only the values of the fist set of notification.
How is that i can get all the values of the attributes and store it in separate variables?
for item in notificationlist: ...