Re: RE: Take 2 - How do you replace comments from XML?
Dominica DeGrandis wrote: > Ok - I left out some important information in my request for help below. > The file I'm working with is a MS .NETFramework system file under > C:\WINNT\Microsoft.NET\Framework\v1.0.3705\CONFIG called machine.config. > It's an XML file. It uses comments to separate sections of configurations. > I'm trying to replace custom configurations under the <appSettings> node > that begins and ends with comments. Ahh... misread your post, sorry. Then you probably want a line oriented thing to plonk in a magic marker tag def insertMarkers(before, after): ifile = open("machine.config") ofile = open("machine-tmp.config", "w") for line in ifile: if line.find(before) != -1: ofile.write("<magic.marker>") ofile.write(line) if line.find(after) != -1: ofile.write("</magic.marker>") ifile.close() ofile.close() if __name__ == "__main__": insertMarkers("Start xxxx.Net", "End xxxx.Net") Now you can select the magic.marker blocks in machine-tmp.config, do whatever you like with that document, and write back to the original minus the tags. It [expletive deleted] for sure, but without knowing exactly what you're trying to do, are you certain that there isn't enough information in the XML (minus comments) to pick out what you need? Bill de hÓra
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format