Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Joaquin Alzola Newsgroups: comp.lang.python Subject: RE: delete from pattern to pattern if it contains match Date: Mon, 25 Apr 2016 10:19:56 +0000 Lines: 75 Message-ID: References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de rttpw8Ktx3XLVXH8YLXg7gJxVLSMoPfubmo2dHnFciXQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.025 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'root': 0.04; 'skip:e 50': 0.05; 'expected.': 0.09; 'message-----': 0.15; '2016': 0.16; 'doesnt': 0.16; 'elem': 0.16; 'executed.': 0.16; 'privilege.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:[ 60': 0.16; 'to:addr:web.de': 0.16; 'wrote:': 0.16; 'tree': 0.18; 'to:name:python-list@python.org': 0.20; 'to:2**1': 0.21; 'xmlns=""': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'specify': 0.27; 'skip:( 20': 0.28; 'does,': 0.29; 'code:': 0.29; 'print': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'probably': 0.31; 'skip:s 30': 0.31; 'statement': 0.32; 'url:python': 0.33; '"")': 0.33; 'skip:- 10': 0.34; 'url:listinfo': 0.34; 'sent:': 0.35; 'could': 0.35; 'subject:': 0.35; 'but': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'charset:us-ascii': 0.37; 'delete': 0.38; 'skip:s 40': 0.38; 'subject:from': 0.39; 'from:': 0.39; 'skip:e 20': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'some': 0.40; 'email addr:gmail.com': 0.62; 'contact': 0.66; 'python-list': 0.66; 'reuse': 0.66; 'here': 0.66; 'email name :python-list': 0.67; 'subject': 0.70; 'finally': 0.70; 'disclose': 0.71; 'subscribers': 0.72; 'otten': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lebara.onmicrosoft.com; s=selector1-lebara-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=JsQlBb4T9SHv+6Ua8TpzQAPRpsSsCJx0MfUzUA2o+Jw=; b=Kd5d20WsZGz6orebS7wh8AOaEIdCF1Hh1bdWCMdoGtXgfuEA1y9+4q7ihekfclCef6FHYxik7SXLA/pDauBct7p8MTmXyfJV9kShYE+s+I+9yra/yEHdQZjI2t62kkSKeWLmCAmEyFeLk+a0f7Vpw4z2GFaZOzBee2LWioDrwmI= Thread-Topic: delete from pattern to pattern if it contains match Thread-Index: AQHRntuRROlwol0+U02RUJfmekSea5+aeZFQ In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: web.de; dkim=none (message not signed) header.d=none;web.de; dmarc=none action=none header.from=lebara.com; x-originating-ip: [212.161.49.106] x-ms-office365-filtering-correlation-id: a9b64e4e-8df6-481e-545f-08d36cf32652 x-microsoft-exchange-diagnostics: 1; HE1PR07MB1356; 5:knRJGRkn4JdB3Mz4scUa/pDq9Jva/GtVs6ALtpVXcxXIV8+MZWDRRPodKsLO+ajNXUd56HFN8qnh6ImJHYEs2IlybBw9PNaIyjSA4OORkAE2L3PFmdKewRBVk54jkXBNzaYVOJM7emh3qYxLGO9HIg==; 24:Mvx+WwcawwOldyYX2ZNWfGUfq17EmG2qWnDaX2aRqB1osm/Z9UqXXJLNT871FiVl5joAon5Jp+sNM7IY7aYgv4AHip/brUc7S45Tb6cnVzk=; 7:f/txcPAhOSRsb5vDtFsOpOUFpj6pDGMrN18Gbdvrt/sLfH/2qCd8tGr+7MA5+8fBt4DfCOxQReAtV+NWEydXaZWrGvc2oj16f0rDBY/TCGDb/RSuKqy3MSy7+cdd4KUHoks5aMKBqMXeKZSkWQt0ks56xrK4tUhBm9LHBqbuCn1O7O4tEyRBXWCbQgqoYEUh x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR07MB1356; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(9101521062)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001); SRVR:HE1PR07MB1356; BCL:0; PCL:0; RULEID:; SRVR:HE1PR07MB1356; x-forefront-prvs: 0923977CCA x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(24454002)(13464003)(19580395003)(5002640100001)(19580405001)(76176999)(5001770100001)(50986999)(189998001)(5004730100002)(5003600100002)(15975445007)(2950100001)(54356999)(1220700001)(9686002)(77096005)(2900100001)(81166005)(1096002)(1720100001)(33656002)(6116002)(106116001)(87936001)(10400500002)(2906002)(107886002)(3660700001)(586003)(86362001)(93886004)(122556002)(3846002)(2501003)(102836003)(74316001)(76576001)(92566002)(11100500001)(5008740100001)(66066001)(3280700002); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR07MB1356; H:HE1PR07MB1356.eurprd07.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM X-OriginatorOrg: lebara.com X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Apr 2016 10:19:56.4060 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d7093539-83cd-4991-b1b3-aacef74cf097 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR07MB1356 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> Xref: csiph.com comp.lang.python:107600 I put some code I did before for the xmlns: xml_root =3D ET.ElementTree(ET.fromstring(xml= _decoded)).getroot() for elem in xml_root.getiterator(): if('{http://request.messagepus= h.interfaces.comviva.com/xsd}shortCode'=3D=3Delem.tag): shortCode =3D (= elem.text).rstrip() if('{http://request.messagepus= h.interfaces.comviva.com/xsd}text'=3D=3Delem.tag): send_text =3D (= elem.text).rstrip() if('{http://request.messagepus= h.interfaces.comviva.com/xsd}item'=3D=3Delem.tag): subscribers =3D= (elem.text).rstrip() result_sms =3D send_sms(subscribers,shortCode= ,send_text) Reuse it. -----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=3Dlebara.com@p= ython.org] On Behalf Of Peter Otten Sent: 25 April 2016 11:14 To: python-list@python.org Subject: Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com wrote: > Here is the code: Finally ;) > import xml.etree.ElementTree as ET > ET.register_namespace("", "http://xmlns.jcp.org/xml/ns/javaee") I don't know what this does, but probably not what you expected. > tree =3D ET.parse('sample.xml') > root =3D tree.getroot() > > for servlet in root.findall('servlet'): > servletname =3D servlet.find('servlet-name').text I think you have to specify the namespace: for servlet in root.findall('{http://xmlns.jcp.org/xml/ns/javaee}servlet'): servletname =3D servlet.find( '{http://xmlns.jcp.org/xml/ns/javaee}servlet-name').text > if servletname =3D=3D "controller": You could have added a print statement to verify that the line below is exe= cuted. > root.remove(servlet) > > tree.write('output.xml') > > This will work if doesnt have below... > > xmlns=3D"http://xmlns.jcp.org/xml/ns/javaee" > xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation=3D"http://xmlns.jcp.org/xml/ns/javaee > http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" -- https://mail.python.org/mailman/listinfo/python-list This email is confidential and may be subject to privilege. If you are not = the intended recipient, please do not copy or disclose its content but cont= act the sender immediately upon receipt.