extra xml header with ElementTree?
Stefan Behnel
stefan.behnel-n05pAM at web.de
Fri May 25 13:09:21 EDT 2007
Tim Arnold wrote:
> Hi, I'm using ElementTree which is wonderful. I have a need now to write out
> an XML file with these two headers:
> <?xml version="1.0" encoding="UTF-8" ?>
> <?NLS TYPE="org.eclipse.help.toc"?>
>
> My elements have the root named tocbody and I'm using:
> newtree = ET.ElementTree(tocbody)
> newtree.write(fname)
>
> I assume if I add the encoding arg I'll get the xml header:
> newtree = ET.ElementTree(tocbody)
> newtree.write(fname,encoding='utf-8')
>
> but how can I get the <?NLS TYPE="org.eclipse.help.toc"?> into the tree?
Try
ET.ProcessingInstruction("NLS", 'TYPE="..."')
Or try lxml.etree instead, it's ET compatible but has very good support for
PIs starting with 1.3beta.
http://codespeak.net/lxml/dev/
Stefan
More information about the Python-list
mailing list