Reputation: 137
I have a python DOM object output, I need to get only the "Elements" from it.
Example:
[<DOM Text node "u'\n\t\t\t'">, <DOM Element: StartTime at 0x397af30>, <DOM Text node "u'\n\t\t\t'">, <DOM Element: EndTime at 0x397afd0>, <DOM Text node "u'\n\t\t'">]
I need output like
StartTime
EndTime
Can you please assist ? Thanks
Upvotes: 3
Views: 976
Reputation: 89305
"I have a python DOM object output, I need to get only the "Elements" from it."
You can filter your list item where nodeType == xml.dom.minidom.Node.ELEMENT_NODE
. For example, assuming that your 'DOM object output' stored in a variable named output
, you can do as follow :
from xml.dom import minidom
.....
.....
result = [item for item in output if item.nodeType == minidom.Node.ELEMENT_NODE]
Upvotes: 3