delete from pattern to pattern if it contains match

harirammanohar at gmail.com harirammanohar at gmail.com
Tue Apr 26 06:31:25 EDT 2016


On Monday, April 25, 2016 at 6:04:24 PM UTC+5:30, Peter Otten wrote:
> harirammanohar at gmail.com wrote:
> 
> >> 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.
> > 
> > But its removing top line
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> 
> The write() method allows you to specify an encoding and/or require an xml 
> declaration:
> 
> https://docs.python.org/dev/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.write

Hi Peter,

Thanks for reminding about basic write method syntax...its working :)


<?xml version='1.0' encoding='iso-8859-1'?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.1" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee                        http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <servlet-mapping>
      <servlet-name>graph</servlet-name>
      <url-pattern>/graph</url-pattern>
    </servlet-mapping>


    <session-config>
      <session-timeout>30</session-timeout>
    </session-config>


Here is the change:

tree.write('output.xml',encoding="ISO-8859-1",xml_declaration=True)

Thank you all especially jussi and pete..



More information about the Python-list mailing list