Advertisement
fmandreoli

Untitled

Nov 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import xml.dom.minidom
  2.  
  3. def printSection(gameBookFile, desiredSect):
  4.         xmlDoc = xml.dom.minidom.parse(gameBookFile)
  5.         sections = xmlDoc.getElementsByTagName("section");
  6.         for sectionN in sections:       # search section
  7.                 num = sectionN.attributes.getNamedItem("number").nodeValue;
  8.                 if num == desiredSect:          # section found
  9.                         textN = sectionN.getElementsByTagName("text")[0].childNodes[0].nodeValue;
  10.                         print("Section "+num)
  11.                         print(textN)                     # print section text
  12.                         choices=sectionN.getElementsByTagName("choice");
  13.                         for choiceN in choices:         # cycle in choices
  14.                                 descrN = choiceN.getElementsByTagName("descr")[0].childNodes[0].nodeValue;
  15.                                 jumpN = choiceN.getElementsByTagName("jump")[0].childNodes[0].nodeValue;
  16.                                 print(descrN+' '+jumpN)
  17.  
  18. desiredSection = "1"
  19. printSection("gamebook.xml", desiredSection)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement