Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107600

RE: delete from pattern to pattern if it contains match

From Joaquin Alzola <Joaquin.Alzola@lebara.com>
Newsgroups comp.lang.python
Subject RE: delete from pattern to pattern if it contains match
Date 2016-04-25 10:19 +0000
Message-ID <mailman.71.1461585209.32212.python-list@python.org> (permalink)
References (7 earlier) <ee696bf4-706f-4113-bb91-d231ebf47b05@googlegroups.com> <lf5d1pew42b.fsf@ling.helsinki.fi> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> <nfkql5$gli$1@ger.gmane.org> <HE1PR07MB135650146927B98CE4240AEBF0620@HE1PR07MB1356.eurprd07.prod.outlook.com>

Show all headers | View raw


I put some code I did before for the xmlns:

                              xml_root = ET.ElementTree(ET.fromstring(xml_decoded)).getroot()
                              for elem in xml_root.getiterator():
                                             if('{http://request.messagepush.interfaces.comviva.com/xsd}shortCode'==elem.tag):
                                                            shortCode = (elem.text).rstrip()
                                             if('{http://request.messagepush.interfaces.comviva.com/xsd}text'==elem.tag):
                                                            send_text = (elem.text).rstrip()
                                             if('{http://request.messagepush.interfaces.comviva.com/xsd}item'==elem.tag):
                                                            subscribers = (elem.text).rstrip()
                              result_sms = send_sms(subscribers,shortCode,send_text)

Reuse it.

-----Original Message-----
From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com@python.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 = ET.parse('sample.xml')
> root = tree.getroot()
>
> for servlet in root.findall('servlet'):
>         servletname = 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 = servlet.find(
        '{http://xmlns.jcp.org/xml/ns/javaee}servlet-name').text

>         if servletname == "controller":

You could have added a print statement to verify that the line below is executed.

>                 root.remove(servlet)
>
> tree.write('output.xml')
>
> This will work if <web-app> </web-app> doesnt have below...
>
> xmlns="http://xmlns.jcp.org/xml/ns/javaee"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   xsi:schemaLocation="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 contact the sender immediately upon receipt.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-18 00:07 -0700
  RE: delete from pattern to pattern if it contains match Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-18 07:49 +0000
    Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-18 01:52 -0700
    Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-18 21:01 -0700
  Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-21 03:17 -0700
    Re: delete from pattern to pattern if it contains match Peter Otten <__peter__@web.de> - 2016-04-21 13:24 +0200
      Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-22 02:00 -0700
        Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-22 02:14 -0700
          Re: delete from pattern to pattern if it contains match Peter Otten <__peter__@web.de> - 2016-04-22 11:50 +0200
            Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-24 23:24 -0700
    Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-21 16:32 +0300
      Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-22 01:59 -0700
        Re: delete from pattern to pattern if it contains match Peter Otten <__peter__@web.de> - 2016-04-22 11:24 +0200
          Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-22 14:10 +0300
            Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-24 23:29 -0700
              Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 10:17 +0300
                Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-25 02:49 -0700
                Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-25 02:53 -0700
                Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 13:37 +0300
                Re: delete from pattern to pattern if it contains match Peter Otten <__peter__@web.de> - 2016-04-25 12:13 +0200
                Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 13:39 +0300
                Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-25 04:02 -0700
                Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 14:28 +0300
                Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-25 04:40 -0700
                Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 15:00 +0300
                Re: delete from pattern to pattern if it contains match Peter Otten <__peter__@web.de> - 2016-04-25 14:33 +0200
                Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-26 03:31 -0700
                Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 13:24 +0300
                RE: delete from pattern to pattern if it contains match Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-25 10:19 +0000

csiph-web