Am 09.06.2015 um 18:22 schrieb Charlie Clark:
Am .06.2015, 12:06 Uhr, schrieb Frederik Elwert
: 1. I had to add an nsmap argument to the creation of "element" in order to prevent an "ns0:" prefix in the output. But this lead to a duplication of the declaration of the default namespace 'http://www.dspin.de/data/textcorpus' on both <TextCorpus> and <tokens>.
If you assign a default namespace then *all* child elements are within this namespace unless otherwise specified. i.e. don't use FQN for child elements.
You mean just to create the child elements by not specifying their namespace? The problem is that I don’t always control the namespace declaration on the parent tag. Using etree.xmlfile() is my resort if dealing with very large files, but normally I just add new sub-trees to an existing document. So I feel it would be a bit shaky to assume a default namespace when generating the sub-trees. So ideally, I’d like etree.xmlfile() to be aware of the current namespace declaration and use the default namespace when it is set on the parent element. This is how lxml deals with regular trees, but xmlfile() seems not to be able to do that.
If you want to pretty print the result then it's hard to beat using the tidy command line tool:
tidy -m --xml file.xml
Since I also serve the XML output on the fly through a web service, I would like to avoid having to do that. But I might do that in this special case, thanks for the hint! Regards, Frederik -- Dr. Frederik Elwert Post-doctoral researcher Project manager SeNeReKo Center for Religious Studies Ruhr-University Bochum Universitätsstr. 150 D-44780 Bochum Room FNO 01/180 Tel. +49-(0)234 - 32 24794