def putcuefile(newdoc, cuedict, cuenum): global firstuuid if firstuuid and cuenum == 0: cueele = ET.SubElement(newdoc, 'Cue', { 'uuid': '{0}'.format(firstuuid), 'num': '{0:003}'.format(cuenum) }) firstuuid = None else: cueele = ET.SubElement(newdoc, 'Cue', { 'uuid': '{0}'.format(uuid.uuid4()), 'num': '{0:003}'.format(cuenum) }) for key in cuedict: print('key: {0}'.format(key)) firstlevelel = ET.SubElement(cueele, key) if type(cuedict[key]) is not dict: print('**') print(cuedict[key]) firstlevelel.text = cuedict[key] else: children = cuedict[key] for child in children: print('child: {0}, childval: {1}'.format( child, children[child])) secondlevel = ET.SubElement(firstlevelel, child) secondlevel.text = children[child] pass return newdoc
def addnewmixerdetails(self, mixer, protocol, mutestyle, countbase): protocolelement = ET.Element('protocol') protocolelement.text = protocol mixer.insert(mixer.__len__(), protocolelement) mutestyleelement = ET.Element('mutestyle', mutestyle) mixer.insert(mixer.__len__(), mutestyleelement) countbaseelement = ET.Element('countbase') countbaseelement.text = '"{0}"'.format(countbase) mixer.insert(mixer.__len__(), countbaseelement)
def __init__(self, cuecharfilename, first_cue_uuid=None, char_list=None): """""" logging.info('In CueChar init') if not path.isfile(cuecharfilename): # build new cuechar file self.cuecharlist = ET.Element('showcontrol') project = ET.SubElement(self.cuecharlist, 'cues') ET.SubElement(project, 'version').text = '1.0' self.add_cue(first_cue_uuid, char_list) self.write(self.cuecharlist, False, cuecharfilename) self.setup_cuechar(cuecharfilename)
def setup_cues(self, cuefilename): logging.info('In CueList setup_cues') self.cuetree = ET.ElementTree(file=cuefilename) self.cuelist = ET.parse(cuefilename) self.cuelist_root = self.cuelist.getroot() self.currentcueindex = 0 self.previouscueindex = 0 self.previewcueindex = 0 self.selectedcueindex = None #self.cues_element = self.cuelist_root.find('cues') #self.cuelist.find(".cues/cue[@num='001']") cues = self.cuelist.findall('.cues/cue') self.cuecount = len(cues)
def __init__(self): self.logger = logging.getLogger('Show') self.logger.info('In configuration.init') self.logger.info('message from configuration') self.settings = {} tree = ET.parse(CFG_PATH) self.doc = tree.getroot() self.logger.debug(ET.tostring(self.doc)) #print('Root tag: {0}'.format(self.doc.tag)) #print('{0} attribs: {1}'.format(self.doc.tag, self.doc.attrib)) self.logger.debug('Root tag: {0}'.format(self.doc.tag)) self.logger.debug('{0} attribs: {1}'.format(self.doc.tag, self.doc.attrib)) self.cfgdict = self.toDict() return
def addnewmixer(self, brand, model): newmixer = ET.Element('mixer', attrib={'mfr': brand, 'model': model}) self.mixers.insert(self.mixers.__len__(), newmixer) self.mixer_list() self.mixer_count = len(self.mixers) return newmixer print()
def setcurrentcuestate(self, cueindex): ''' Constructor ''' #print('{0:03}'.format(cueindex)) thiscue = self.cuelist.find("./cue[@num='" + '{0:03}'.format(cueindex) + "']") print(ET.dump(thiscue)) try: ents = thiscue.find('Entrances') # print(ET.dump(ents)) # print(ents.text) if ents != None: entlist = ents.text for entidx in entlist.split(","): self.mutestate[entidx.strip()] = 1 except: print('Entrances Index ' + '{0:03}'.format(cueindex) + ' not found!') try: exts = thiscue.find('Exits') if exts != None: extlist = exts.text for extidx in extlist.split(","): self.mutestate[extidx.strip()] = 0 except: print('Exits Index ' + '{0:03}'.format(cueindex) + ' not found!')
def __init__(self, cfgdict): self.logger = logging.getLogger('ShowConf') self.logger.info('In ShowConf init.') self.cfgdict = cfgdict self.settings = {} self.equipment = {} showconf_file = self.cfgdict['configuration']['project'][ 'folder'] + '/' + self.cfgdict['configuration']['project']['file'] self.logger.debug(showconf_file) tree = ET.parse(showconf_file) self.doc = tree.getroot() # print(doc) self.projecttodict() self.logger.info('settings dictionary: {}'.format(self.settings)) self.equiptodict() self.logger.info('equipment dictionary: {}'.format(self.equipment)) # #Get mixer chan to actor/char map file name # mxrmap = self.doc.find('mixermap') # attribs = mxrmap.attrib # self.settings["mxrmap"] = attribs['file'] #Get mixer chan to actor/char map file name # cues = self.doc.find('cuefile') # attribs = cues.attrib # self.settings["cuefile"] = attribs['file'] # print(self.settings) # self.name = self.doc.find('title') # print('ShowConf.__init__ name: ',self.name.text) # self.settings['title'] = self.name.text return
def write(self, newxml, revision=True, filename=''): """save a new characters file. If revision is true, save with a revision number i.e. this essentially makes a backup of the config file, typically call with revision=True before an add or insert If revision=False, save in the file specified by filename""" newdoctree = ET.ElementTree(newxml) if filename == '': logging.debug('Configuration not saved, no filename provided!') msgBox = QtWidgets.QMessageBox() msgBox.setText('Configuration not saved, no filename provided!') msgBox.exec_() return rev = 1 if revision: oldroot, extension = path.splitext(filename) while path.isfile(oldroot + '-{0}'.format(rev) + extension): rev += 1 shutil.copyfile(filename, oldroot + '-{0}'.format(rev) + extension) logging.debug('Configuration written to: ' + oldroot + '-{0}'.format(rev) + extension) newdoctree.write(filename, xml_declaration=True) logging.debug('Configuration written to: ' + filename) return
def __init__(self, mixerconf_file, mixername, mixermodel): # # dictionary of input sliders, index format: [Chnn] # each entry is a InputControl object self.inputsliders = {} # dictionary of output sliders, index format: [Chnn] # each entry is a OutputControl object self.outputsliders = {} # dictionary of mutestyle for the mixer # mutestyle referes to how the mixer indicates the channel is muted # for example, the Yamaha 01V indicates a channel is un-muted with an illuminated light # other mixer indicate a muted channel with an illuminated light # mutestyle['mutestyle'] will be the string 'illuminated' or 'non-illumnated' # as read from <mixerdefs>.xml for each particular mixer # for mutestyle['illuminated'], mutestyle['mute'] will be 0, mutestyle['unmute'] will be 1 # for mutestyle['non-illuminated'], mutestyle['mute'] will be 1, mutestyle['unmute'] will be 0 self.mutestyle = {} mixerdefs = ET.parse(mixerconf_file) mixers = mixerdefs.getroot() #print('mixers: ' + str(mixers)) for mixer in mixers: #print(mixer.attrib) mxattribs = mixer.attrib if 'model' in mxattribs.keys(): if mxattribs['model'] == mixermodel and mxattribs['mfr'] == mixername: #print('found') break self.protocol = mixer.find('protocol').text #print('protocol: ' + self.protocol) self.mutestyle['mutestyle'] = mixer.find('mutestyle').text if self.mutestyle['mutestyle'] == 'illuminated': self.mutestyle['mute'] = 0 self.mutestyle['unmute'] = 1 else: self.mutestyle['mute'] = 1 self.mutestyle['unmute'] = 0 ports = mixer.findall('port') for port in ports: portattribs = port.attrib #print(portattribs) if portattribs['type'] == 'input': #print(portattribs['cnt']) self.input_count = int(portattribs['cnt']) #print(self.input_count) for x in range(1, self.input_count + 1): sldr = InputControl(x,'In' + '{0:02}'.format(x)) self.inputsliders['Ch' + '{0:02}'.format(x)] = sldr elif portattribs['type'] == 'output': #print(portattribs['cnt']) self.output_count = int(portattribs['cnt']) #print(self.output_count) for x in range(1, self.output_count + 1): sldr = OutputControl(x,'Out' + '{0:02}'.format(x)) self.outputsliders['Ch' + '{0:02}'.format(x)] = sldr #print(self.inputsliders)
def __init__(self, cuefilename): ''' Constructor cuelist is a tree object with all cues for the show ''' self.cuelist = ET.parse(cuefilename) self.currentcueindex = 0 self.previewcueindex = 0
def __init__(self, mixerconf_file, mixername, mixermodel): # # dictionary of input sliders, index format: [Chnn] # each entry is a InputControl object self.inputsliders = {} # dictionary of output sliders, index format: [Chnn] # each entry is a OutputControl object self.outputsliders = {} # dictionary of mutestyle for the mixer # mutestyle referes to how the mixer indicates the channel is muted # for example, the Yamaha 01V indicates a channel is un-muted with an illuminated light # other mixer indicate a muted channel with an illuminated light # mutestyle['mutestyle'] will be the string 'illuminated' or 'non-illumnated' # as read from <mixerdefs>.xml for each particular mixer # for mutestyle['illuminated'], mutestyle['mute'] will be 0, mutestyle['unmute'] will be 1 # for mutestyle['non-illuminated'], mutestyle['mute'] will be 1, mutestyle['unmute'] will be 0 self.mutestyle = {} mixerdefs = ET.parse(mixerconf_file) mixers = mixerdefs.getroot() #print('mixers: ' + str(mixers)) for mixer in mixers: #print(mixer.attrib) mxattribs = mixer.attrib if 'model' in mxattribs.keys(): if mxattribs['model'] == mixermodel and mxattribs[ 'mfr'] == mixername: #print('found') break self.protocol = mixer.find('protocol').text #print('protocol: ' + self.protocol) self.mutestyle['mutestyle'] = mixer.find('mutestyle').text if self.mutestyle['mutestyle'] == 'illuminated': self.mutestyle['mute'] = 0 self.mutestyle['unmute'] = 1 else: self.mutestyle['mute'] = 1 self.mutestyle['unmute'] = 0 ports = mixer.findall('port') for port in ports: portattribs = port.attrib #print(portattribs) if portattribs['type'] == 'input': #print(portattribs['cnt']) self.input_count = int(portattribs['cnt']) #print(self.input_count) for x in range(1, self.input_count + 1): sldr = InputControl(x, 'In' + '{0:02}'.format(x)) self.inputsliders['Ch' + '{0:02}'.format(x)] = sldr elif portattribs['type'] == 'output': #print(portattribs['cnt']) self.output_count = int(portattribs['cnt']) #print(self.output_count) for x in range(1, self.output_count + 1): sldr = OutputControl(x, 'Out' + '{0:02}'.format(x)) self.outputsliders['Ch' + '{0:02}'.format(x)] = sldr
def addnewcue(self, cue_data=[]): cues_element = self.cuelist.find(".cues") cues = cues_element.findall(".cue") cue_count = len(cues) newcue = ET.Element('cue',attrib={'uuid':'{0}'.format(uuid.uuid4()), 'num':'{0:03}'.format(cue_count)}) #newcue = ET.Element('cue',attrib={'uuid':'{0}'.format(uuid.uuid4()), 'num':'{0:03}'.format(self.cuecount)}) for i in range(cue_subelements.__len__()): newele = ET.SubElement(newcue, cue_subelements[i].replace('_','')) newele.text = cue_data[i] cues_element.append(newcue) # ET.dump(cues_element) cues = self.cuelist.findall('.cues/cue') self.cuecount = len(cues) # self.cuelist.write('addelementtest.xml') return [newcue.get('uuid'), newcue.get('num')]
def makenewstrip(self, mixer, striptype, stripcount, stripname): newstrip = ET.Element('strip', attrib={ 'type': striptype, 'cnt': stripcount, 'name': stripname }) # newcontrol = ET.SubElement(newstrip, 'fader') mixer.insert(mixer.__len__(), newstrip) return newstrip
def save_file(self, obj): qfd = QtWidgets.QFileDialog() (name, file_type) = QtWidgets.QFileDialog.getSaveFileName(qfd, 'Save File', "","XML files (*.xml)") try: xmlfile = open(name,'w') tree = ET(obj.xmlroot) tree.write(xmlfile, encoding='unicode') xmlfile.close() except: print("No file saved") pass
def convert_dictionaries_to_xml_tree(dictionaries, root_name, element_name): root = ET.Element(root_name) for dictionary in dictionaries: for key in dictionary: if dictionary[key] is None: text_value = 'null' else: text_value = dictionary[key] temp = ET.SubElement(element_name, key) temp.text = text_value return ET(root)
def __init__(self, mixerconf_file): self.mixerdefsorig = ET.parse(mixerconf_file) self.mixerdefs = copy.deepcopy(self.mixerdefsorig) self.mixers = self.mixerdefs.getroot() self.mixer_count = len(self.mixers) self.mfr_list = [] self.model_list = [] self.protocol = '' self.mutestyle = '' self.s_countbase = '' self.mixer_list() self.selected_mixer = None self.defs_modified = False
def setcueelement(self, cueindex, element_text, element_name): # find the cue specified by cueindex #thiscue = self.cuelist.find("./cue[@num='" + '{0:03}'.format(cueindex) + "']") thiscue = self.cuelist.find(".cues/cue[@num='" + '{0:03}'.format(cueindex) + "']") try: cuetype = thiscue.find(element_name) if cuetype != None: cuetype.text = element_text else: cuetype = ET.SubElement(thiscue, 'Levels') cuetype.text = element_text except: print('Cue element {0} for index {1:03} not found!'.format(element_name, cueindex)) self.cuelist.write('update.xml')
def add_cue(self, cue_uuid, char_list): print('CueChar add_cue, uuid: {}'.format(cue_uuid)) cues_element = self.cuecharlist.find('.cues') new_cue = ET.SubElement(cues_element, 'cue', {'uuid': cue_uuid}) for char in char_list: new_char_ele = ET.SubElement(new_cue, 'char', {'uuid': char[0]}) ET.SubElement(new_char_ele, 'mute').text = '1' ET.SubElement(new_char_ele, 'onstage').text = '0' ET.SubElement(new_char_ele, 'level').text = '0' ET.SubElement(new_char_ele, 'eq', attrib={'uuid': 'eq uuid'}) ET.SubElement(new_char_ele, 'routing', attrib={'uuid': 'routing uuid'})
def insertcue(self, cueindex, cue_data=[]): # cueidx is the index that we're inserting above, so # create an empty place by incrementing the cue num for this and each subsequent cue for anidx in reversed(range(cueindex, self.cuecount)): cuenum = '{0:03}'.format(anidx) thiscue = self.cuelist.find(".cues/cue[@num='"+cuenum+"']") thisidx = thiscue.get('num') thiscue.set('num', '{0:03}'.format(int(thisidx) + 1)) print(thiscue.get('num')) # now we have an empty place # create the new cue # show = self.cuelist.getroot() # ET.dump(show) cues_element = self.cuelist.find(".cues") newcue = ET.Element('cue',attrib={'uuid':'{0}'.format(uuid.uuid4()), 'num':'{0:03}'.format(cueindex)}) for i in range(cue_subelements.__len__()): newele = ET.SubElement(newcue, cue_subelements[i].replace('_','')) newele.text = cue_data[i] cues_element.insert(cueindex + 1, newcue) # show.insert(cueindex, newcue) # ET.dump(show) cues = self.cuelist.findall('.cues/cue') self.cuecount = len(cues) return
def updateFromDict(self): newdoc = ET.Element('show_control') for key in self.cfgdict: print('key: {0}'.format(key)) firstlevelel = ET.SubElement(newdoc, key) if type(self.cfgdict[key]) is not dict: print('**') print(self.cfgdict[key]) firstlevelel.text = self.cfgdict[key] else: children = self.cfgdict[key] for child in children: print('child: {0}, childval: {1}'.format( child, children[child])) secondlevel = ET.SubElement(firstlevelel, child) child_item = children[child] if type(child_item) is dict: for item in child_item: thirdlevel = ET.SubElement(secondlevel, item) thirdlevel.text = child_item[item] else: secondlevel.text = children[child] pass return newdoc
def getmixermap(mapfile): global firstuuid mixermap = ET.parse(mapfile) mixermap_root = mixermap.getroot() firstmap = mixermap_root.find('mixermap') firstuuid = firstmap.get('uuid') charcount = int(firstmap.get('charcount')) chars = firstmap.findall('input') chardict = {} for char in chars: cnum = int(char.attrib['chan']) mxrid = int(char.attrib['mixerid']) char = char.attrib['char'] chardict[char] = 'M{0:1}ch{1:02}'.format(mxrid, cnum) return chardict
def chars_toxmldoc(self): """Create a new showcontrol element from the current state of the list of character tuples""" newcharelements = {} showcontrol = ET.Element('showcontrol') ET.SubElement(showcontrol, 'version').text = '1.0' chars = ET.SubElement(showcontrol, 'chars') for char in self.char_list: charchild = ET.SubElement(chars, 'char', attrib={'uuid': char[0]}) ET.SubElement(charchild, 'name').text = char[1] ET.SubElement(charchild, 'actor').text = char[2] return showcontrol
def __init__(self, cuefilename, chancount): ''' Constructor cuelist is a tree object with all cues for the show mutestate is a dictionary that maintains the current mute state based on what entrances and exits appear in the cuelist levelstate is a dictionary that maintains the current level of each slider currentindex is an integer that indicates the current cue previewcueindex is an integer that indicates the cue being previewed , if a preview is active ''' self.cuelist = ET.parse(cuefilename) self.mutestate = {} for x in range(1, chancount + 1): self.mutestate['ch' + '{0}'.format(x)] = 0 self.levelstate = {} self.currentcueindex = 0 self.previewcueindex = 0
def toXMLdoc(self): # get cues xml # self.cuelist = ET.parse('/home/mac/Shows/CharTest/CharTest_cuesx.xml') self.cuelist = ET.parse('/home/mac/Shows/Fiddler/Fiddler_cuesx.xml') self.cuelist_root = self.cuelist.getroot() self.cues = self.cuelist_root.findall(".cues/cue") for cue in self.cues: cue_id_element = cue.find('.Id') cue_id = cue_id_element.text if '.' in cue_id: page, line = cue_id.split('.') else: page = '' line = cue_id print('integer: {}, fraction: {}'.format(page, line)) cue_id_element.text = line return
def add_new_char(self, new_char_uuid): cues = self.cuecharlist.findall('.cues/cue') for cue in cues: chars = cue.findall(".char") print('In add_new_char, char count before: {}'.format(len(chars))) new_char_ele = ET.SubElement(cue, 'char', {'uuid': new_char_uuid}) ET.SubElement(new_char_ele, 'mute').text = '1' ET.SubElement(new_char_ele, 'onstage').text = '0' ET.SubElement(new_char_ele, 'level').text = '0' ET.SubElement(new_char_ele, 'eq', attrib={'uuid': 'eq uuid'}) ET.SubElement(new_char_ele, 'routing', attrib={'uuid': 'routing uuid'})
def __init__(self, mapfilename): ''' Constructor ''' logging.info('In MixerCharMap.') self.maptree = ET.parse(mapfilename) self.maproot = self.maptree.getroot() self.current_map_index = 0 self.previous_map_index = 0 maps = self.maproot.findall("./mixermap") self.map_list = [] for key in range(len(maps)): print(key) map = self.maproot.find("./mixermap[@count='" + str(key) + "']") self.map_list.append(map.get('uuid')) print(self.map_list) self.mapcount = len(self.map_list) # this is not the count= in the mixermap element, # but the count of mixermaps in the xml file maps = None
def __init__(self, showconf_file): self.settings = {} tree = ET.parse(showconf_file) doc = tree.getroot() print(doc) #Get mixer info mixer = doc.find('mixer') print('ShowConf::', mixer.attrib) mxattribs = mixer.attrib try: print(mxattribs['model']) self.settings['mxrmodel'] = mxattribs['model'] except: self.settings['mxrmodel'] = '' print('No Mixer model defined') if self.settings['mxrmodel'] == '': self.settings['mxrmodel'] = '' try: print(mxattribs['mfr']) self.settings['mxrmfr'] = mxattribs['mfr'] except: self.settings['mxrmfr'] = 'Default' print('No Mixer manufacturer defined') if self.settings['mxrmfr'] == '': self.settings['mxrmfr'] = 'Default' #Get mixer chan to actor/char map file name mxrmap = doc.find('mixermap') attribs = mxrmap.attrib self.settings["mxrmap"] = attribs['file'] #Get mixer chan to actor/char map file name mxrcues = doc.find('mixercues') attribs = mxrcues.attrib self.settings["mxrcue"] = attribs['file'] print(self.settings) self.name = doc.find('name') print('ShowConf.__init__ name: ',self.name.text) self.settings['name'] = self.name.text
def setup_cast(self, charfilename): """Load the specified xml file """ logging.info('In Chars setup_cast') if not path.isfile(charfilename): of = open(charfilename, mode='w') of.write('<?xml version="1.0" encoding="UTF-8"?>\n') of.write('<show_control>\n') of.write(' <version>1.0</version >\n') of.write(' <chars>\n') of.write(' <char uuid="{}">\n'.format(uuid.uuid4())) of.write(' <name>""</name>\n') of.write(' <actor>""</actor>\n') of.write(' </char>\n') of.write(' </chars>\n') of.write('</show_control>\n') of.close() self.char_element_tree = ET.parse(charfilename) self.charlist_root = self.char_element_tree.getroot() self.chars_element = self.charlist_root.find('chars') self.char_element_list = self.chars_element.findall('char') self.charcount = len(self.char_element_list) return
def build_char_file(self): self.maptree = ET.parse('/home/mac/SharedData/ShowSetups/Shows/Fiddler/MixerMap.xml') self.maproot = self.maptree.getroot() maps = self.maproot.findall("./mixermap") self.map_list = [] map = self.maproot.find("./mixermap[@count='0']") inputs = map.findall('input') # build file name name = 'FiddlerChar' cf = os.path.join('/home/mac/SharedData/ShowSetups/Shows/Fiddler/', '{}_char.xml'.format(name)) of = open(cf,mode='w') of.write('<?xml version="1.0" encoding="UTF-8"?>\n') of.write('<show_control>\n') of.write(' <version>1.0</version >\n') of.write(' <chars>\n') for mxrin in inputs: actor = mxrin.get('actor') char = mxrin.get('char') print(actor,char) of.write(' <char uuid="{}">\n'.format(uuid.uuid4())) of.write(' <name>"{}"</name>\n'.format(char)) of.write(' <actor>"{}"</actor>\n'.format(actor)) of.write(' </char>\n') of.write(' </chars>\n') of.write('</show_control>\n') of.close() # self.mm_element_list = ET.parse('/home/mac/SharedData/ShowSetups/Shows/CharTest/MixerMap.xml') # self.mm_list_root = self.char_element_list.getroot() # self.mm__element = self.charlist_root.find('showcontrol') # self.char_element_list = self.chars_element.findall('char') # tf = os.path.join(SHOWS, 'CharTest', '{}_char.xml'.format('FromMixerMap')) # # for char in self.char_element_list: # print() return
result = { "$" : parseChildren(x.getchildren()) } else: result = dict(prepend.items() + { "$" : parseChildren(x.getchildren()) }.items()) if tag in final: if type(final[tag]) is not types.ListType: final[tag] = [final[tag]] final[tag].append(result) else: final[tag] = result return final #print parseChildren([ET.XML('<tag>txt-value</tag>')]) #print parseChildren([ET.XML('<tag><tag2>txt-value</tag2></tag>')]) #print parseChildren([ET.XML('<tag><tag2>txt-value1</tag2><tag2>txt-value2</tag2></tag>')]) #print parseChildren([ET.XML('<tag ns="ns-value" />')]) #print parseChildren([ET.XML('<tag xmlns:ns="ns-value" />')]) #print parseChildren([ET.XML('<tag xmlns="root-value" xmlns:ns="ns-value" />')]) #print parseChildren([ET.XML('<ns:tag attr="attr-value" />')]) #print parseChildren([ET.XML('<tag attr="attr-value">txt-value</tag>')]) #print parseChildren([ET.XML('<ns:tag attr="attr-value">txt-value</tag>')]) import sys x = ET.parse(sys.argv[1]).getroot() print parseChildren([x]) print ET.tostring(x)
def __init__(self, mapfilename): ''' Constructor ''' self.maplist = ET.parse(mapfilename)
def toXMLdoc(self): showcontrol = ET.Element('showcontrol') cues = ET.SubElement(showcontrol, 'cues') ET.SubElement(cues, 'version').text = '1.0' cue = ET.SubElement(cues, 'cue', attrib={'uuid':'{0}'.format(uuid.uuid4()), 'num':'{0:03}'.format(0)}) ET.SubElement(cue, 'Id').text = '0' ET.SubElement(cue, 'Act').text = '0' ET.SubElement(cue, 'Scene').text = 'Pre Show' ET.SubElement(cue, 'Page').text = '0' ET.SubElement(cue, 'Title').text = 'Initial State' ET.SubElement(cue, 'CueCall').text = 'Program Start' ET.SubElement(cue, 'CueType').text = 'Stage,Mixer,Sound' ET.SubElement(cue, 'Mutes').text = '' ET.SubElement(cue, 'Entrances').text = '' ET.SubElement(cue, 'Exits').text = '' ET.SubElement(cue, 'Levels').text = '' ET.SubElement(cue, 'OnStage').text = '' ET.SubElement(cue, 'Note1').text = '' ET.SubElement(cue, 'Note2').text = '' ET.SubElement(cue, 'Note3').text = '' ET.SubElement(cue, 'map').text = '0' return showcontrol
def get_xml_for_string(cls, s): """ Returns a tuple containing the XML tree and root objects """ root = ET.fromstring(s) return ET.ElementTree(element=root), root
def get_xml_for_file(cls, f): """ Returns a tuple containing the XML tree and root objects """ tree = ET.parse(f) return tree, tree.getroot()
elem = ET.SubElement(root, "attackpoints") elem.text = "2" elem = ET.SubElement(root, "keeperpoints") elem.text = "3" #for child in root: # print (child.tag, child.attrib) outFilename = "./output.xml" html = ET.Element("html") body = ET.SubElement(html, "body") ET.ElementTree(root).write(outFilename) #ET.ElementTree(root).prettyprint(outFilename) print(ET.tostring(root, pretty_print=True)) filename = "./TeamA.xml" tree = ET.parse(filename) elem = tree.getroot() print ("------- child level by child level ------") print("elem.tag=",elem.tag, " elem.attrib=", elem.attrib) for child in elem: if child.tag == "players" : print ("child.tag=", child.tag, " | child.attrib=",child.attrib, " | child.text=", child.text) for subchild in child: print ("subchild.tag=", subchild.tag,