Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!news2.euro.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*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; 'jan': 0.18; '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; 'file': 0.32; 'structure': 0.32; 'suggestion': 0.32; 'text,': 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; 'xml': 0.37; 'maintaining': 0.37; 'subject:: ': 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; 'received:fios.verizon.net': 0.84; 'subject:Search': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Search and replace text in XML file? Date: Sat, 28 Jul 2012 03:17:45 -0400 References: <5535f70f-4542-451f-8b08-a62b45d15c11@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: <5535f70f-4542-451f-8b08-a62b45d15c11@googlegroups.com> 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343459910 news.xs4all.nl 6912 [2001:888:2000:d::a6]:54820 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26154 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. -- Terry Jan Reedy