Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:two': 0.04; 'value,': 0.04; 'subject:Python': 0.05; 'python': 0.08; 'pointers': 0.09; 'recognise': 0.09; 'run.': 0.09; 'subject:files': 0.09; 'essentially': 0.10; 'output': 0.10; 'am,': 0.12; 'broken': 0.12; 'cc:addr:python-list': 0.15; 'both.': 0.16; 'duplicates': 0.16; 'eliminating': 0.16; 'ignored,': 0.16; 'module).': 0.16; 'patch.': 0.16; 'subject:XML': 0.16; 'terms,': 0.16; 'wrote:': 0.16; "wouldn't": 0.17; '(which': 0.19; 'trying': 0.20; 'compatible': 0.21; 'cc:no real name:2**0': 0.21; '(i.e.,': 0.21; 'header:In-Reply-To:1': 0.22; 'figure': 0.23; 'runs': 0.23; 'differ': 0.23; 'libraries': 0.24; 'stefan': 0.24; 'times,': 0.24; 'creating': 0.25; 'exercise': 0.25; 'tests': 0.25; 'module': 0.26; 'load': 0.26; 'testing': 0.26; 'tried': 0.27; "i'm": 0.27; 'depends': 0.28; 'problem': 0.29; 'cc:addr:python.org': 0.29; 'subject:?': 0.30; '(e.g.': 0.30; 'functional': 0.30; 'xml': 0.30; 'usually': 0.30; 'quite': 0.31; 'developers': 0.31; 'that,': 0.32; 'idea': 0.32; 'header:User-Agent:1': 0.33; 'rest': 0.33; 'there': 0.33; 'match': 0.33; 'field,': 0.34; 'file.': 0.34; 'duplicate': 0.34; 'identical': 0.34; 'latter': 0.34; 'something': 0.35; 'things': 0.35; 'question': 0.35; 'test': 0.35; 'external': 0.35; 'file': 0.35; 'cc:2**1': 0.36; 'two': 0.37; 'run': 0.37; 'but': 0.37; 'using': 0.37; 'could': 0.37; 'patch': 0.38; 'some': 0.38; 'hoping': 0.38; 'received:192': 0.38; 'easier': 0.38; 'should': 0.38; 'itself.': 0.38; 'difficult': 0.39; 'that.': 0.39; 'format.': 0.39; 'tool': 0.39; 'files': 0.39; 'doing': 0.39; 'subject:: ': 0.39; 'might': 0.40; 'data': 0.40; 'quick': 0.60; 'more': 0.61; 'your': 0.61; 'efficient': 0.61; 'full': 0.62; 'results': 0.64; 'here': 0.64; 'due': 0.66; 'memory,': 0.67; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'average': 0.80; 'am.': 0.84; 'flexible,': 0.84; 'hand?': 0.84; 'sum': 0.88; 'manual,': 0.91; 'subject:there': 0.91 Date: Thu, 12 Jan 2012 12:02:41 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 MIME-Version: 1.0 To: dreadpiratejeff@gmail.com Subject: Re: Is there a way to merge two XML files via Python? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:epdcrj9IiAXg4umCs+WVrc2gVJoO0YWdKVnq8gu2FwJ 6Bl/WCa5X5cZxK4+2E9MaCHiL4Swsq/+7GhBIqCGL9GEIrt97B Wz3k8zm9LCkapnPzHoWe9zf4h2vAMAetQ/qya2yGKSpEn2wJCi W5DTHyOv/p3m/ZXyff/5jpkc9vJo8yTwvwI2uNkCVNfsKhka/U TuG+wlxGlY3rE8ULDg+rFCpAxHnH0neMm24gllYJu2NoDjxU6v gRtk7TycsN9VLIhXC5iE70VPvmnB/vuEXMGgxCQqs1qr4O4c5N bZVwlyQ6FIz0c3uDaV5Tia8UW7rTe2pAZzRhhjwItabbEt/ayK P+ICx7t0Z6yJkHEINvLg= Cc: python-list@python.org, Stefan Behnel X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name 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: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1326387773 news.xs4all.nl 6965 [2001:888:2000:d::a6]:42677 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18879 On 01/12/2012 11:39 AM, Stefan Behnel wrote: > J, 12.01.2012 17:04: >> This is more a theory exercise and something I'm trying to figure out, >> and this is NOT a homework assignment... >> >> I'm trying to make a tool I use at work more efficient :) >> >> So this is at test tool that generates an XML file as it's output that >> is eventually used by a web service to display test results and system >> information. >> >> The problem is that the testing is broken down into to different runs: >> Functional and Automated where the Functional tests are all manual, >> then the automated tests are run separately, usually overnight. >> >> Each of those test runs generates essentially an identical XML file. >> What I want to learn is a way to merge them. > Ok - how large are these files? (i.e., do they easily fit into memory?) > > >> In abstract terms, the idea is essentially to diff the two files >> creating a patch and then use that patch to merge the two files into a >> single XML file. > I wouldn't go through patch. If they fit into memory, just load both, merge > one into the other eliminating duplicates, and save that. > > Or rather, load just one and process the other one incrementally using > ElementTree's iterparse(). > > >> SO what I was hoping I could get pointers on from those of you who are >> experienced in using Python with XML is what python libraries or means >> are there for working with XML files specifically, and how easy or >> difficult would this be? > Depends on how easy it is to recognise duplicates in your specific data > format. Once you've managed to do that, the rest is trivial. > > >> I'm also doing research on my own in my spare time on this, but I also >> wanted to ask here to get the opinion of developers who are more >> experienced in working with XML than I am. > I recommend looking at the stdlib xml.etree.ElementTree module or the > external lxml package (which contains the ElementTree compatible lxml.etree > module). The latter will (likely) make things easier due to full XPath > support and some other goodies, but ElementTree is also quite quick and > easy to use by itself. > > Stefan > Question for jeff: Have you tried doing it by hand? Do you know when a duplicate should be ignored, when it should be replicated, when it should be represented by incrementing a count? xml is very flexible, but the final reader of your file may not be so flexible. (e.g. if it has to match a wsdl) If two runs differ only by some timing field, then you might need to sum those times, and produce an average in the final run. Or a max value, or both. -- DaveA