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


Groups > comp.lang.python > #107601

Re: delete from pattern to pattern if it contains match

Path csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Jussi Piitulainen <jussi.piitulainen@helsinki.fi>
Newsgroups comp.lang.python
Subject Re: delete from pattern to pattern if it contains match
Date Mon, 25 Apr 2016 15:00:09 +0300
Organization A noiseless patient Spider
Lines 58
Message-ID <lf58u01sxti.fsf@ling.helsinki.fi> (permalink)
References <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <lf5fuufqe81.fsf@ling.helsinki.fi> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <nfcqjs$guu$1@ger.gmane.org> <mailman.11.1461317067.2861.python-list@python.org> <lf57ffpdhl5.fsf@ling.helsinki.fi> <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> <mailman.70.1461579263.32212.python-list@python.org> <lf5h9eqrmzx.fsf@ling.helsinki.fi> <95f0d9a7-69ff-43bf-a856-8fa62fe8a985@googlegroups.com> <lf5d1perkqn.fsf@ling.helsinki.fi> <15f2e9ff-7624-4886-bcd9-c3e9d21db328@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx02.eternal-september.org; posting-host="305c68510616a2e7ac08bcd2ff1598bd"; logging-data="12734"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1856uYHZlK9DmBTDOdn1TqwMl3XJ2Uojmk="
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:FDskhTU4UFvMxhamB8ZLBxN223A= sha1:nKOBnfU82pqlRKh1zi1Zmvw5UDY=
Xref csiph.com comp.lang.python:107601

Show key headers only | View raw


harirammanohar@gmail.com writes:

> On Monday, April 25, 2016 at 4:58:15 PM UTC+5:30, Jussi Piitulainen wrote:
>> harirammanohar@gmail.com writes:
>> 
>> > On Monday, April 25, 2016 at 4:09:26 PM UTC+5:30, Jussi Piitulainen wrote:
>> >> Peter Otten writes:
>> >> 
>> >> > harirammanohar@gmail.com wrote:
>> >> >
>> >> >> Here is the code:
>> >> >
>> >> > Finally ;)
>> >> 
>> >> :)
>> >
>> > name space issue can be resolved registering name space i have no
>> > issue with that, only concern is xml parser has no effect when http
>> > things are added...
>> 
>> No, the parser works fine. Your attempt to register a default namespace
>> didn't work. Those "http things" *are* the namespace issue!
>> 
>> The following version of your code works. *Try it.* It finds the servlet
>> element in the document object, removes it, and writes out XML text
>> without the servlet element. (It seems to invent another namespace
>> prefix. That doesn't change the meaning of the document.)
>> 
>> import xml.etree.ElementTree as ET
>> 
>> ns = { 'x' : "http://xmlns.jcp.org/xml/ns/javaee" }
>> 
>> tree = ET.parse('sample.xml')
>> root = tree.getroot()
>> 
>> for servlet in root.findall('x:servlet', ns):
>>     servletname = servlet.find('x:servlet-name', ns).text
>>     if servletname == "controller":
>>         root.remove(servlet)
>> 
>> tree.write('output.xml')
>
> yup its working well if i include register namespace, else i am
> getting ns:0 in every line of output.xml.

That's a namespace prefix for each element name that is in the default
namespace. If the ET.register_namespace has the effect of making that
the default namespace in the output, fine, you can use it.

The important thing is that you can read your output.xml back in, using
the XML parser, and it has the intended meaning.

> But its removing top line
> <?xml version="1.0" encoding="ISO-8859-1"?>

Not a problem. You can still read your output.xml back in, using the XML
parser, and it will have the same meaning as it would have had with this
declaration.

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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