3 from xml
.dom
import minidom
, Node
7 def GetQuestions(self
):
10 for q
in self
.file.getElementsByTagName("question"):
11 id = q
.getAttribute ("id")
14 for c
in q
.childNodes
:
15 if c
.nodeType
== Node
.ELEMENT_NODE
:
18 for child
in c
.childNodes
:
19 if child
.nodeType
== Node
.TEXT_NODE
:
20 content
.append(child
.nodeValue
)
22 strContent
= string
.join(content
)
24 if c
.nodeName
== "textquestion":
25 textquestion
= strContent
26 elif c
.nodeName
== "textanswer":
27 if c
.getAttribute("correct") == "true":
32 answers
.append ([answer
, correct
])
34 self
.questions
.append ([id, textquestion
,answers
])
39 def GetChapters(self
):
41 for c
in self
.root
.childNodes
:
42 if c
.nodeType
== Node
.ELEMENT_NODE
:
43 if c
.nodeName
== "chapter":
44 id1
= c
.getAttribute("id")
45 name1
= c
.getAttribute("name")
46 for d
in c
.childNodes
:
47 if d
.nodeType
== Node
.ELEMENT_NODE
:
48 if d
.nodeName
== "chapter":
49 id2
= d
.getAttribute("id")
50 name2
= d
.getAttribute("name")
51 for e
in d
.childNodes
:
52 if e
.nodeType
== Node
.ELEMENT_NODE
:
53 if e
.nodeName
== "chapter":
54 id3
= e
.getAttribute("id")
55 name3
= e
.getAttribute("name")
57 def GetBasicProperties(self
):
60 def AskQuestion(self
,id):
61 for q
in self
.questions
:
66 self
.question
= str(q
[1])
67 self
.correct
= "a" #FIXME
68 self
.answera
= q
[2][0][0][0]
69 self
.answerb
= q
[2][1][0][0]
70 self
.answerc
= q
[2][2][0][0]
71 self
.answerd
= q
[2][3][0][0]
73 def __init__(self
,filename
="Questions/questions.xml"):
74 self
.filename
=filename
75 self
.file = minidom
.parse (self
.filename
)
76 self
.root
= self
.file.documentElement
83 #q.AskQuestion("TB305")