Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xml.dom.minidom
- def printSection(gameBookFile, desiredSect):
- xmlDoc = xml.dom.minidom.parse(gameBookFile)
- sections = xmlDoc.getElementsByTagName("section");
- for sectionN in sections: # search section
- num = sectionN.attributes.getNamedItem("number").nodeValue;
- if num == desiredSect: # section found
- textN = sectionN.getElementsByTagName("text")[0].childNodes[0].nodeValue;
- print("Section "+num)
- print(textN) # print section text
- choices=sectionN.getElementsByTagName("choice");
- for choiceN in choices: # cycle in choices
- descrN = choiceN.getElementsByTagName("descr")[0].childNodes[0].nodeValue;
- jumpN = choiceN.getElementsByTagName("jump")[0].childNodes[0].nodeValue;
- print(descrN+' '+jumpN)
- desiredSection = "1"
- printSection("gamebook.xml", desiredSection)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement