Hi, On Thu, 21 May 2015 11:18:38 +0200 Stefan Behnel <stefan_ml@behnel.de> wrote:
[...]
Maybe there is a better method to remove the prolog of an XML file, but I only found this one.
Any idea?
Why not serialise only the root element?
Well, not sure if I understood you correct, but I don't think this will work. The bigger problem is because of entities. I need to (temporarily) remove the DOCTYPE because I want to retain the complete prolog, fix something in my XML, and write back prolog plus the fixed XML. Unfortunately, this copious method is needed as I don't want to touch the DOCTYPE header. For example, if I have something like this: <!DOCTYPE article [ <!ENTITY % entities SYSTEM "entity-decl.ent"> %entities; ]> the complete set of my "entity-decl.ent" file is read in and will appear in the subset of the DTD after I write it to a file. As I want to keep the DOCTYPE as it is, I have to remove the DOCTYPE declaration somehow. For that reason, I need to know the exact(!) line number of the start-tag to remove the whole prolog. Unfortunately, I haven't found a method where I can tell lxml "leave DOCTYPE as is is, never touch it". Does that make sense to you? -- Gruß/Regards, Thomas Schraitle