3 from xml
.dom
import minidom
, Node
9 def GetQuestions(self
):
17 for q
in self
.file.getElementsByTagName("question"):
18 id = q
.getAttribute ("id")
20 hint
= self
.GetHint(id)
23 for c
in q
.childNodes
:
24 if c
.nodeType
== Node
.ELEMENT_NODE
:
27 for child
in c
.childNodes
:
28 if child
.nodeType
== Node
.TEXT_NODE
:
29 content
.append(child
.nodeValue
)
31 strContent
= string
.join(content
)
33 if c
.nodeName
== "textquestion":
34 textquestion
= strContent
35 elif c
.nodeName
== "textanswer":
36 if c
.getAttribute("correct") == "true":
41 answers
.append ([answer
, correct
])
43 self
.questions
.append ([id, textquestion
,answers
, hint
])
50 for h
in self
.root
.getElementsByTagName ("hint"):
51 id = h
.getAttribute ("question")
53 for child
in h
.childNodes
:
54 if child
.nodeType
== Node
.TEXT_NODE
:
55 content
.append(child
.nodeValue
)
57 strContent
= string
.join(content
)
59 ss
= strContent
.split("<a href=\"http://")[1].split("\">")[0]
61 self
.hints
.append ([id, ss
])
72 def GetChapters(self
):
77 for c
in self
.root
.childNodes
:
78 if c
.nodeType
== Node
.ELEMENT_NODE
:
79 if c
.nodeName
== "chapter":
80 id1
= c
.getAttribute("id")
81 name1
= c
.getAttribute("name")
82 for d
in c
.childNodes
:
83 if d
.nodeType
== Node
.ELEMENT_NODE
:
84 if d
.nodeName
== "chapter":
85 id2
= d
.getAttribute("id")
86 name2
= d
.getAttribute("name")
87 for e
in d
.childNodes
:
88 if e
.nodeType
== Node
.ELEMENT_NODE
:
89 if e
.nodeName
== "chapter":
90 id3
= e
.getAttribute("id")
91 name3
= e
.getAttribute("name")
93 def GetBasicProperties(self
):
95 print "Get basic properties"
97 #self.title = self.root.getAttribute("title")
101 #exam id="T" name="Technische Kenntnisse / Klasse A" duration="90" maxerrorpoints="13"
104 def AskQuestion(self
,id):
106 print "Ask question:",id
108 for q
in self
.questions
:
114 self
.correct
= "a" #FIXME
115 self
.answera
= q
[2][0][0][0]
116 self
.answerb
= q
[2][1][0][0]
117 self
.answerc
= q
[2][2][0][0]
118 self
.answerd
= q
[2][3][0][0]
121 def __init__(self
,filename
="Questions/questions.xml"):
122 self
.filename
=filename
123 self
.file = minidom
.parse (self
.filename
)
124 self
.root
= self
.file.documentElement
131 #q.AskQuestion("TB305")