Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:text': 0.05; 'subject:file': 0.07; 'definition,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'automation,': 0.16; 'message-id:@dough.gmane.org': 0.16; 'processor,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:XML': 0.16; 'wrote:': 0.17; 'windows': 0.19; 'changes': 0.20; 'file.': 0.20; 'project,': 0.24; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'replace': 0.27; 'header:X-Complaints-To:1': 0.28; 'run': 0.28; "i'm": 0.29; 'knows': 0.30; 'file': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'structure': 0.32; 'suggestion': 0.32; 'text,': 0.33; 'anyone': 0.33; 'to:addr:python-list': 0.33; 'text': 0.34; 'or,': 0.34; 'basis.': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:org': 0.36; 'editor': 0.37; 'xml': 0.37; 'maintaining': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'email addr:gmail.com': 0.63; 'request.': 0.64; 'processor.': 0.84; 'subject:Search': 0.84; 'received:89': 0.86 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Search and replace text in XML file? Date: Sat, 28 Jul 2012 09:29:12 +0100 References: <5535f70f-4542-451f-8b08-a62b45d15c11@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-89-240-163-202.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: X-Antivirus: avast! (VPS 120727-1, 27/07/2012), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343464174 news.xs4all.nl 6966 [2001:888:2000:d::a6]:33334 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26155 On 28/07/2012 08:17, Terry Reedy wrote: > On 7/27/2012 9:23 PM, todd.tabern@gmail.com wrote: >> I'm looking to search an entire XML file for specific text and >> replace that text, while maintaining the structure of the XML file. > > For a one-off project, or for experimentation, I would use a proper > text-editor* and run through with search/replace. For automation, use > Jason's suggestion of .replace, perhaps on a line-by-line basis. > > * By definition, such only make changes you request. Notepad++ is one > such on Windows. You do not want a word or document processor, or, for > simple xml oblivious text substitutions, an xml processor. Such things > often make changes of various sorts. > I highly recommend the use of notepad++. If anyone knows of a better text editor for Windows please let me know :) -- Cheers. Mark Lawrence.