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.
I used another approach to get Elemnts by ID (meaning the XML-attribute "id"), since I wanted to only use xml.dom.minidom.
Here is an example from my work:
#import minidom
from xml.dom.minidom import parse as p
#parse your XML-document
cmmn_doc = p("document.xml")
#Get all child nodes of your root-element or any element surrounding your "target" (in my example "cmmn:casePlanModel")
notelist = cmmn_doc.getElementsByTagName("cmmn:casePlanModel")[0].childNodes#Now find the element via the id-tag
def find_element(id):i=0for i in range(len(notelist)):if notelist[i].getAttribute("id") == id:return notelist[i].nodeName #(or whatever you want to do)#Call find_element with the id you are looking for
find_element(id)
XML from the example:
<cmmn:casePlanModel id="CasePlanModel_1" name="A CasePlanModel"><cmmn:planItem id="PlanItem_1" definitionRef="Task_1" /><cmmn:planItem id="PlanItem_08uai3q" definitionRef="HumanTask_0pgsk2i" /><cmmn:planItem id="PlanItem_0crahv8" definitionRef="HumanTask_0jvecsr"><cmmn:itemControl id="PlanItemControl_0tdwp8g"><cmmn:repetitionRule id="RepetitionRule_03ky93m" /><cmmn:requiredRule id="RequiredRule_1klzaio" /><cmmn:manualActivationRule id="ManualActivationRule_1rek2bf" /></cmmn:itemControl></cmmn:planItem><cmmn:planItem id="PlanItem_08kswcr" definitionRef="HumanTask_14zxi11" /><cmmn:planItem id="PlanItem_12b1nkx" definitionRef="ProcessTask_10xuu3g"><cmmn:exitCriterion id="EntryCriterion_09gio4l" sentryRef="Sentry_0hst9b5" /></cmmn:planItem><cmmn:planItem id="PlanItem_1v34h5m" definitionRef="CaseTask_0hwjce3"><cmmn:entryCriterion id="EntryCriterion_1j8r6j1" sentryRef="Sentry_1ii8w5d" /></cmmn:planItem><cmmn:planItem id="PlanItem_0wroqsx" definitionRef="EventListener_17yxe7z" /><cmmn:sentry id="Sentry_0hst9b5" /><cmmn:sentry id="Sentry_1ii8w5d"><cmmn:planItemOnPart id="PlanItemOnPart_1gt5jrc" sourceRef="PlanItem_12b1nkx"> <cmmn:standardEvent>complete</cmmn:standardEvent>
</cmmn:planItemOnPart><cmmn:planItemOnPart id="PlanItemOnPart_01b6uw3" sourceRef="PlanItem_0wroqsx"> <cmmn:standardEvent>occur</cmmn:standardEvent>
</cmmn:planItemOnPart></cmmn:sentry><cmmn:task id="Task_1" name="Simple Task" /><cmmn:humanTask id="HumanTask_0pgsk2i" name="Human Task" /><cmmn:humanTask id="HumanTask_0jvecsr" name="Human_Blocking" isBlocking="false" /><cmmn:humanTask id="HumanTask_14zxi11" name="Human_mit_Anhang"><cmmn:planningTable id="PlanningTable_1yxv7gm"><cmmn:discretionaryItem id="DiscretionaryItem_0ne79yh" definitionRef="DecisionTask_1ecc5v8" /></cmmn:planningTable></cmmn:humanTask><cmmn:decisionTask id="DecisionTask_1ecc5v8" name="Descritionary to Human Task" /><cmmn:processTask id="ProcessTask_10xuu3g" name="Prozess Task" /><cmmn:caseTask id="CaseTask_0hwjce3" name="Case Task" /><cmmn:eventListener id="EventListener_17yxe7z" name="EventListener" /></cmmn:casePlanModel>
I found this way more convenient.