def check_and_fix_stickytext(xrefelement) : if 'scope' in xrefelement.attrib: return; parts = xrefelement.attrib['href'].split('#') topics = None if parts[0] == '' : #within this file topics = root.findall(".//topic[@id='" + parts[1] + "']") else : otherroot = getxmlroot(foldername + parts[0]) topics = otherroot.findall(".//topic[@id='" + parts[1] + "']") if len(topics) == 1: #link is fine so lets check the sticky text title = topics[0].find('title') if title.text != xrefelement.text : print (title.text) print (xrefelement.text) print ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxx') xrefelement.text = title.text global changemade changemade = changemade + 1
tree.write(filename) with open(filename, 'r+') as f: content = f.read() f.seek(0, 0) #make sure you get to the start of the file f.write('<?xml version="1.0" encoding="UTF-8"?>' + "\n") f.write('<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Composite//EN" "technicalContent/dtd/ditabase.dtd" [' + "\n") f.write('<!-- Begin Document Specific Declarations -->' + "\n") f.write('<!-- End Document Specific Declarations -->' + "\n") f.write(']>' + "\n") f.write(content) f.close() xmlfiles = glob.glob('C:/aaWork/p4v_ws/theoden/depot/EN/Docs/TechComm Suite/2015/fm/scripting/*.xml') changemade = 0 for xmlfile in xmlfiles : print (xmlfile) root = getxmlroot(xmlfile) classElements = root.findall("*") for classElement in classElements : if 'class' in classElement.attrib : del classElement.attrib['class'] changemade = changemade + 1 iteratetree(classElement) try : if changemade > 0 : writechanges(tree,xmlfile) except: print (sys.exc_info()[0]) print ("done")