3 from xml
.dom
import minidom
, Node
10 def GetQuestions(self
):
19 for q
in self
.file.getElementsByTagName("question"):
20 id = q
.getAttribute ("id")
22 hint
= self
.GetHint(id)
25 for c
in q
.childNodes
:
26 if c
.nodeType
== Node
.ELEMENT_NODE
:
29 for child
in c
.childNodes
:
30 if child
.nodeType
== Node
.TEXT_NODE
:
31 content
.append(child
.nodeValue
)
33 strContent
= string
.join(content
)
35 if c
.nodeName
== "textquestion":
36 textquestion
= strContent
37 elif c
.nodeName
== "textanswer":
38 if c
.getAttribute("correct") == "true":
43 answers
.append ([answer
, correct
])
45 self
.questions
.append ([id, textquestion
,answers
, hint
])
53 for h
in self
.root
.getElementsByTagName ("hint"):
54 id = h
.getAttribute ("question")
56 for child
in h
.childNodes
:
57 if child
.nodeType
== Node
.TEXT_NODE
:
58 content
.append(child
.nodeValue
)
60 strContent
= string
.join(content
)
62 ss
= strContent
.split("<a href=\"http://")[1].split("\">")[0]
64 self
.hints
.append ([id, ss
])
75 def GetChapters(self
):
80 for c
in self
.root
.childNodes
:
81 if c
.nodeType
== Node
.ELEMENT_NODE
:
82 if c
.nodeName
== "chapter":
83 id1
= c
.getAttribute("id")
84 name1
= c
.getAttribute("name")
85 for d
in c
.childNodes
:
86 if d
.nodeType
== Node
.ELEMENT_NODE
:
87 if d
.nodeName
== "chapter":
88 id2
= d
.getAttribute("id")
89 name2
= d
.getAttribute("name")
90 for e
in d
.childNodes
:
91 if e
.nodeType
== Node
.ELEMENT_NODE
:
92 if e
.nodeName
== "chapter":
93 id3
= e
.getAttribute("id")
94 name3
= e
.getAttribute("name")
96 def GetBasicProperties(self
):
98 print "Get basic properties"
100 #self.title = self.root.getAttribute("title")
104 #exam id="T" name="Technische Kenntnisse / Klasse A" duration="90" maxerrorpoints="13"
107 def AskQuestion(self
,id):
109 print "Ask question:",id
111 for q
in self
.questions
:
118 self
.series
= self
.Random()
120 self
.correct
= ["a","b","c","d"][s
.index(0)]
121 self
.answera
= q
[2][s
[0]][0][0]
122 self
.answerb
= q
[2][s
[1]][0][0]
123 self
.answerc
= q
[2][s
[2]][0][0]
124 self
.answerd
= q
[2][s
[3]][0][0]
125 self
.answercorrect
= self
.answera
#FIXME
128 def RealAnswer(self
,answer
):
131 realchar
= ["a","b","c","d"][[a
[s
[0]],a
[s
[1]],a
[s
[2]],a
[s
[3]]].index(answer
)]
146 def __init__(self
,filename
="Questions/questions.xml"):
147 self
.filename
=filename
148 self
.file = minidom
.parse (self
.filename
)
149 self
.root
= self
.file.documentElement