On Monday, April 25, 2016 at 6:04:24 PM UTC+5:30, Peter Otten wrote: > harirammano...@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.. -- https://mail.python.org/mailman/listinfo/python-list